[SciPy-user] Looking for function that returns indicies acc'd to condition

Michael Sorich mike_sorich at hotmail.com
Wed Dec 17 09:41:32 CST 2003


Hi Gary,

I think nonzero is what you are looking for:

>>> from Numeric import *
>>> a = array((1,2,3,4,5))
>>> print nonzero(a>3)
[3 4]
>>>

As per numpy manual "nonzero() returns an array containing the indices
of the elements in a that are nonzero. These indices only make
sense for 1d arrays, so the function refuses to act on anything else."

Cheers,

Michael Sorich


-----Original Message-----
From: scipy-user-bounces at scipy.net [mailto:scipy-user-bounces at scipy.net]
On Behalf Of Gary Pajer
Sent: Wednesday, 17 December 2003 8:57 AM
To: SciPy Users List
Subject: [SciPy-user] Looking for function that returns indicies acc'd
to condition

This function must exist in Numeric or scipy, but I can't find it.

Given an array, return an array (or list) of indicies corresponding to
elements that satisfy a condition.

I.e.,
a = array((1,2,3,4,5))
find_index(a>3)

returns [3,4]

tia,
gary

_______________________________________________
SciPy-user mailing list
SciPy-user at scipy.net
http://www.scipy.net/mailman/listinfo/scipy-user



More information about the SciPy-user mailing list