'How to check if a list item is in a 2d array in python [duplicate]

Hi guys I'm trying to check if a particular is list item is in a 2d array in python if that make sense. below is what I have tried.

from numpy import random

x = random.choice(range(0, 9), size=(6, 2))

print([2, 5] in x)

This runs but returns the wrong result. It just checks if 2 or 5 is in the 2d array and returns true else false.

for example.. a result from the above code is below

 >>>[[6 4]
 [5 5]
 [7 3]
 [5 1]
 [8 2]
 [1 8]]

so if I want to be able to check if [1 8] is in the 2d array above and return a true or false. Please any ideas? Thanks



Solution 1:[1]

If you are checking for 2nd array:

print([2,5] in x[1]) 

However, If you want the same random samples for each execution, you need to apply seed

from numpy import random
import numpy as np
np.random.seed(4)
x = random.choice(range(0, 9), size=(6, 2))

print(x)
print(x[1])
print([1,5] in x[1])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 K.Tamang