[Numpy-discussion] getting position index from array

Ruby Stevenson ruby185 at gmail.com
Fri Jan 20 09:21:10 EST 2012


Exactly what I need - thank you very much.

Ruby

On Thu, Jan 19, 2012 at 11:33 PM, Benjamin Root <ben.root at ou.edu> wrote:
>
>
> On Thursday, January 19, 2012, Ruby Stevenson <ruby185 at gmail.com> wrote:
>> hi, all
>>
>> I am a newbie on numpy ... I am trying to figure out, given an array,
>> how to get back position value based on some conditions.
>> Say, array([1, 0, 0, 0 1], and I want to get a list of indices where
>> it is none-zero, [ 0 , 4 ]
>>
>> The closest thing I can find from the doc is select(), but I can't
>> figure out how to use it properly.
>>
>> Thanks for your help.
>>
>> Ruby
>>
>
> np.nonzero()
>
> Note that you typically use it with a Boolean array result like "a >= 4".
>  Also note that it returns a tuple of index lists, on for each dimension.
>  This can the be feed back into the array to get the values as a flat array.
>
> Ben Root
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list