get array element
robert.kern at gmail.com
Thu Apr 10 23:43:25 CEST 2008
Bryan.Fodness at gmail.com wrote:
> I have an array, and I would like to get the indice value.
> a = array([13,14,15,16])
> I would like something like a.getindice(15)
> If I want 15 it would return 2
You will want to ask numpy questions on the numpy mailing list. If you don't
mention that you are using numpy here, people get confused.
Anyways, if your array is sorted, use a.searchsorted(15). If it isn't sorted,
then you can find all of the indices equal to the value with the following:
In : from numpy import *
In : a = array([13,14,15,16])
In : nonzero(a == 15)
"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 Python-list