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

Benjamin Root ben.root@ou....
Wed Oct 6 09:27:39 CDT 2010


On Wed, Oct 6, 2010 at 7:23 AM, Nicolas Bigaouette <nbigaouette@gmail.com>wrote:

> 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
>
>
Wouldn't it be more technically correct to use numpy.nonzero()?  Returning
the index is a special behavior of not specifying the second argument to
numpy.where().

Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20101006/40d8f12a/attachment.html 


More information about the NumPy-Discussion mailing list