[Numpy-discussion] populating an array

Robert Kern robert.kern@gmail....
Mon Mar 2 11:33:57 CST 2009


On Mon, Mar 2, 2009 at 05:08, Brennan Williams
<brennan.williams@visualreservoir.com> wrote:
> 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
> overall.
> 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, J, K = numpy.mgrid[0:self.ni, 0:self.nj, 0:self.nk]
self.iarray = I.ravel()
self.jarray = J.ravel()
self.karray = K.ravel()

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the Numpy-discussion mailing list