Hi,

In Matlab, the command

[i,j] = find(mat >= 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 one-dimensional 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>=2 dimensions, returns a tuple T of N arrays

such that the condition is true at indices (T[0][i],...,T[N-1][i]).

"""

sh = condition.shape

if len(sh) == 1:

return nonzero(condition)

idx = indices(sh)

cond = ravel(condition)

return tuple([compress(cond, ravel(idx[i]))

for i in range(len(sh))])

## ···

--

Jouni K Seppänen

http://www.iki.fi/jks