[Numpy-discussion] ToyFDTDpython on Freshmeat yesterday

Chris Barker chrishbarker at home.net
Thu Sep 6 09:36:03 CDT 2001


Rob wrote:
> Only slowdown was dumping the E fields into a file every few
> ticks to generate the movie.  I know there must be better ways to dump
> an array than use indexing-  

If you want to dump the binary data, you can use:

file.write(array.tostring)

If you need an ASCI representation, you can use various forms of:

format_string = '%f '* A.shape[1] + '\n' 
for r in range(A.shape[0]):
	file.write(format_string%(tuple(A[r,:])))

You could probably use map to speed it up a little as well.

I'd love to see an array-oreinted version of fscanf and fprintf to make
this faster and easier, but I have yet to get around to writing one.

-Chris



-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------




More information about the Numpy-discussion mailing list