[Numpy-discussion] Translation of Matlab function find()

Miquel Poch miquel.poch at gmail.com
Wed Mar 21 04:23:51 EDT 2007


Hi,

I'm trying to translate some Matlab functions. I don't know exactly how make
and equivalent for function find(). This give us the index of an array where
a condition it's true.

I've found some options like this one: (a>0).nonzero(), where a is the array
and (a>0) the condition. But the problem appear with this function return.
It's something like this:

>>> from numpy import *
>>> a=array([0,1,0,1,2,0,1,2,0,0])
>>> print a
[0 1 0 1 2 0 1 2 0 0]
>>> b=(a>0).nonzero()
>>> print b
(array([1, 3, 4, 6, 7]),)
>>> print (a>0).nonzero()
(array([1, 3, 4, 6, 7]),)

I can't acces to b data, doing something like b[x]. Why b is not an array?

I think another possible is use where() function, also avilable in numpy
library. It's better or worse?

Thanks in advance,
Miquel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070321/fa01bd55/attachment.html>


More information about the NumPy-Discussion mailing list