[Numpy-discussion] how to efficiently build an array of x, y, z points

David Goldsmith d.l.goldsmith@gmail....
Tue Mar 2 20:46:00 CST 2010


On Tue, Mar 2, 2010 at 6:29 PM, Brennan Williams <
brennan.williams@visualreservoir.com> wrote:

> I'm reading a file which contains a grid definition. Each cell in the
> grid, apart from having an i,j,k index also has 8 x,y,z coordinates.
> I'm reading each set of coordinates into a numpy array. I then want to
> add/append those coordinates to what will be my large "points" array.
> Due to the orientation/order of the 8 corners of each hexahedral cell I
> may have to reorder them before adding them to my large points array
> (not sure about that yet).
>
> Should I create a numpy array with nothing in it and then .append to it?
> But this is probably expensive isn't it as it creates a new copy of the
> array each time?
>
> Or should I create a zero or empty array of sufficient size and then put
> each set of 8 coordinates into the correct position in that big array?
>
> I don't know exactly how big the array will be (some cells are inactive
> and therefore don't have a geometry defined) but I do know what its
> maximum size is (ni*nj*nk,3).
>

Someone will correct me if I'm wrong, but this problem - the "best" way to
build a large array whose size is not known beforehand - came up in one of
the tutorials at SciPyCon '09 and IIRC the answer was, perhaps surprisingly,
build the thing as a Python list (which is optimized for this kind of
indeterminate sequence building) and convert to a numpy array when you're
done.  Isn't that what was recommended, folks?

DG


>
> Thanks
>
> Brennan
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100302/5d141659/attachment.html 


More information about the NumPy-Discussion mailing list