pacodelumberg
pacodelumberg

Reputation: 2274

matching 1d arrays in 2d arrays in python

I am trying to compare a one dimensional array in a collection of 1 dimensional array using python. For example:

import numpy as np;
data= np.array( [  [1,2] , [2,3] ,[3,4], [1,2] , [0,9] ])
#I want to get the indexes of [1,2] which are 0 and 3 for above list

Does anyone have an idea how to implement that in python?

Upvotes: 2

Views: 2035

Answers (1)

unutbu
unutbu

Reputation: 879501

In [116]: data = np.array( [  [1,2] , [1,3] ,[3,4], [1,2] , [0,9] ])

In [117]: np.where(np.prod(data == [1,2], axis = -1))
Out[117]: (array([0, 3]),)

Upvotes: 4

Related Questions