David Goldsmith wrote: > > > On Tue, Mar 2, 2010 at 6:29 PM, Brennan Williams > <brennan.willi...@visualreservoir.com > <mailto:brennan.willi...@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? > Build a list of floating point values, then convert to an array and shape accordingly? Or build a list of small arrays and then somehow convert that into a big numpy array? I've got 24 floating point values which I've got in an array of shape (8,3) but I could easily have those in a list rather than an array and then just keep appending each small list of values to a big list and then do the final conversion to the array - I'll try that and see how it goes.
Brennan > DG > > > > Thanks > > Brennan > > > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org <mailto:NumPy-Discussion@scipy.org> > http://mail.scipy.org/mailman/listinfo/numpy-discussion > > > ------------------------------------------------------------------------ > > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion