[Numpy-discussion] trying to speed up the following....

Brennan Williams brennan.williams at visualreservoir.com
Tue Mar 24 19:29:34 EDT 2009


I have an array (porvatt.yarray) of ni*nj*nk values.
I want to create two further arrays.

activeatt.yarray is of size ni*nj*nk and is a pointer array to an active 
cell number. If a cell is inactive then its activeatt.yarray value will be 0

ijkatt.yarray is of size nactive, the number of active cells (which I 
already know). ijkatt.yarray holds the ijk cell number for each active cell.


My code looks something like...

           activeatt.yarray=zeros(ncells,dtype=int)
           ijkatt.yarray=zeros(nactivecells,dtype=int)

            iactive=-1
            ni=currentgrid.ni
            nj=currentgrid.nj
            nk=currentgrid.nk
            for ijk in range(0,ni*nj*nk):
              if porvatt.yarray[ijk]>0:
                iactive+=1
                activeatt.yarray[ijk]=iactive
                ijkatt.yarray[iactive]=ijk

I may often have a million+ cells.
So the code above is slow.
How can I speed it up?

TIA

Brennan




More information about the NumPy-Discussion mailing list