Hi,
In Matlab, the command
[i,j] =3D find(mat >=3D 3)
causes i and j to hold the indices where the condition holds. (If
there is only one output argument, it will hold indices to the
flattened version of the condition.) Matplotlib's mlab.find() seems to
work for onedimensional arrays only.
Here's what I'm using to emulate Matlab's find; it only seems to work
with Numeric, not numarray, and I have no idea whether this is an
efficient way to achieve the goal. I was going to suggest that the
utility be included in matplotlib, but perhaps it should then be
generalized to work with numarray as well. I wonder if anyone has any
ideas on how to do this? I'm a newcomer to matplotlib (and Numeric,
etc.), so please do point out if there is a simpler way to achieve the
effect of Matlab's find.
def find(condition):
"""
Return the indices where condition is true.
For arrays of N>=3D2 dimensions, returns a tuple T of N arrays
such that the condition is true at indices (T[0][i],...,T[N1][i]).
"""
sh =3D condition.shape
if len(sh) =3D=3D 1:
return nonzero(condition)
idx =3D indices(sh)
cond =3D ravel(condition)
return tuple([compress(cond, ravel(idx[i]))=20
for i in range(len(sh))])
=20
Jouni K Sepp=E4nen
http://www.iki.fi/jks
