[Numpy-discussion] [numpy-discussion] Transform 3d data
Tue Oct 19 05:05:50 CDT 2010
I have the following problem:
I acquire a (evenly spaced) 3d field of 3d vectors from a HDF5 data file:
>>> import tables
now, the data is organized in "nested arrays"... so, when I have, say, 300
data points on the x-axis, 200 data points on the y-axis and 100 data points
on the z-axis, I get an array with the shape
>>> (300, 200, 100, 3)
When I now want to see a 3D arrow-plot of this field, I use:
>>> from enthought.mayavi import mlab as m
and this works just fine. Here, the arrays (x and y and z) *each* contain
one field component (i,e. into one spatial direction) at 300x200x100 points
in a 3D array.
Now, I would like to have this data in another format, so I can for example
save it to a textfile with pylab.savetxt. What I would like are six arrays,
each 1d, three for the coordinates and three for the field components. Since
I didn't know any better, I wrote the following procedure:
def transform_3d_data_(field,lowerBounds,upperBounds): #field is the same as
above, lowerBounds and upperBounds each contain three values for x,y,z
import pylab as p
will become the spatial coordinates, ex,ey,ez will become the field
for xi in range(field.shape): #for each x coordinate...
for yi in range(field.shape): #for each y coordinate...
for zi in range(field.shape): #for each z coordinate...
#x, y, z coordinate
#to xx, yy, zz ....
ex.append(field[xi][yi][zi]) #and also
ey.append(field[xi][yi][zi]) #add this field composition
ez.append(field[xi][yi][zi]) #to ex, ey, ez.
xx,yy,zz,ex,ey,ez=[p.array(_) for _ in [xx,yy,zz,ex,ey,ez]]
, so I get the desired six 1D-arrays xx,yy,zz for the coordinates and
ex,ey,ez for the field components. It works.
Now my question: there has to be a better way to get this re-organization,
right? This one here is much too slow, obviously. Is there maybe a single
command for pylab that does this?
Thanks in advance, cheers
PS. I'm new to this messaging board, and I was wondering if there is a
"normal" forum as well? I can't even search through the archives at
http://mail.scipy.org/pipermail/numpy-discussion/ :( have there ever been
discussions/initiatives about porting the mailing list archives for example
to a phpBB based forum?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion