[Numpy-discussion] populating an array
Mon Mar 2 05:08:49 CST 2009
Ok... I'm using Traits and numpy.
I have a 3D grid with directions I,J and K.
I have NI,NJ,NK cells in the I,J,K directions so I have NI*NJ*NK cells
I have data arrays with a value for each cell in the grid.
I'm going to store this as a 1D array, i.e. 1....ncells where
ncells=NI*NJ*NK rather than as a 3D array
Apart from lots of other data arrays that will be read in from external
files, I want to create I, J and K data arrays
where the 'I' array contains the I index for the cell, the 'J' array the
J index etc.
I haven't used numpy extensively and I'm coming from a Fortran/C
background so I'm hideously inefficient.
At the moment I have something like....
for icell in arange(1,self.ncells+2):
rn2ijk is defined as...
Obviously I can improve my use of rn2ijk as for a start I'm
recalculating nij for every cell (and I can have anything from a few
thousand to a few million cells).
But I'm sure I could do this more efficiently by probably starting off
with a 3d array, looping over i,j,k and then reshaping it into a 1d array.
More information about the Numpy-discussion