[Numpy-discussion] index of a value in an array

Nicolas Bigaouette nbigaouette@gmail....
Wed Oct 6 07:23:46 CDT 2010


On Wed, Oct 6, 2010 at 5:26 AM, Chris Withers <chris@simplistix.co.uk>wrote:

> Hi All,
>
> Given an array such as:
>
> array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>
> How can I find the index of a particular number in the array?
>
> (ie: if it was a list, I'd do [1,2,3,4].index(3))
>
> cheers,
>
> Chris
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>

Try with numpy.where(array == value) and plain "array == value"
IIRC, the first will return an array the size of the found elements and the
second will return an array (or list?) of True/False.
Either can be used as "index = numpy.where()" and "index = (array == value)"
and then "array[index]".
N
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20101006/09185036/attachment.html 


More information about the NumPy-Discussion mailing list