Tissuebox
Tissuebox

Reputation: 1056

checking if a pair of value is inside a 2D array python

Given an array arr defined as follows

arr = np.arange(4).reshape((2,2))

I want to check if a pair of value [0,1] for exemple is inside my array

I tried np.isin() but it consider the pair of value as two individual value. anyone knows a way to fix this?

Upvotes: 3

Views: 4323

Answers (3)

MAFiA303
MAFiA303

Reputation: 1317

not sure what previously written was what OP wanted

try this

([0,1] == arr).all(axis = 1).any()

Upvotes: 3

MarocCoder
MarocCoder

Reputation: 11

np.any(my_array[:, 0] == value)

Upvotes: 1

R. S. Nikhil Krishna
R. S. Nikhil Krishna

Reputation: 4210

You can simply run

print([0,1] in arr)

to see if [0,1] exists in the first level loop. It should return True in the example you have provided

Upvotes: 2

Related Questions