[SciPy-user] nonzero and the matlab equivalent of find

Robert Kern robert.kern@gmail....
Sun Jul 12 17:05:59 CDT 2009


On Sun, Jul 12, 2009 at 17:03, Robert Kern<robert.kern@gmail.com> wrote:

> There isn't really a function that does this out-of-box, but here is
> how to do it:
>
> In [30]: nonzero((a[:,0] == 1) | (a[:,1] == 1))[0]
> Out[30]: array([0, 1, 2])

Or more generally:

In [34]: nonzero(logical_or.reduce(a == array([1,1]), axis=1))[0]
Out[34]: array([0, 1, 2])

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the SciPy-user mailing list