 # find() applied on multidimensional arrays

It's simpler in numarray:

> i,j = where(z<0.5)

> For numeric it's more work:

> ind = where(z.flat < 0.5) i = ind//z.shape j = ind %
> z.shape

> One could turn this into a function for Numeric (to handle
> all dimensionalities, etc)

I think you meant to use "nonzero" rather than "where" for Numeric...

from matplotlib.numerix import where, nonzero
from matplotlib.numerix.mlab import rand

z = rand(4,5)

# It's simpler in numarray:
i,j = where(z<0.5)
print i,j

# For numeric it's more work:
ind = nonzero(z.flat < 0.5)
i = ind//z.shape
j = ind % z.shape
print i,j

I also think wrapping this functionality into the find function in mpl
is a good idea... I frequently miss it.

JDH

Yes, indeed.

···

On May 17, 2005, at 11:30 AM, John Hunter wrote:

> It's simpler in numarray:

> i,j = where(z<0.5)

> For numeric it's more work:

> ind = where(z.flat < 0.5) i = ind//z.shape j = ind %
> z.shape

> One could turn this into a function for Numeric (to handle
> all dimensionalities, etc)

I think you meant to use "nonzero" rather than "where" for Numeric...