[Numpy-discussion] finding index in an array...

josef.pktd@gmai... josef.pktd@gmai...
Fri Jun 12 18:32:59 CDT 2009


On Fri, Jun 12, 2009 at 7:08 PM, fred<petit.frederic@free.fr> wrote:
> Hi,
>
> Say I have an array A with shape (10,3) and
>
> A[3,:] = [1,2,3]
>
> I want to find the index of the array in which I have these values [1,2,3].
>
> How can I do that?
>
> The only workaround I have found is to use a list:
>
> A.tolist().index([1,2, 3])
>
> That works fine, but is there a better solution (without using list, for
> instance)?
>

something like this should work to find rows with specific elements,
if I understand you correctly.

np.nonzero(A.view([('',float)]*3) == np.array((1,2,3),[('',float)]*3))[0]

It creates an extra dimension, that needs to be removed with [0], but
it takes to long now, to remember how to get rid of it.

Josef

> TIA.
>
>
> Cheers,
>
> --
> Fred
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the Numpy-discussion mailing list