I'm an ex-Matlab user trying to come up to speed with python and numpy.  I'm
confused on how to use the Numpy functions nonzero() and where().  In
matlab, the equivalent function (find(a>0) ) would return an array, whereas
in numpy, where() or nonzero() will return a single element tuple.  For
example:

In [35]: x = [ 0, 0, 0, 99, 0, 1, 5]
# and I wish to file the index of the first non-zero element of x - which is
3.

In [36]: from numpy import nonzero
In [37]: i=nonzero(x)
In [38]: i
Out[38]: (array([3, 5, 6]),)
In [39]: i[0]
Out[39]: array([3, 5, 6])

so nonzero() has output a tuple with a single element = the string
'array([3, 5, 6])'
How do I convert this string (or the original tuple)  into an array where
the first element = 3 (the index of the first non-zero element of my
original array x).
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to