0

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

0

1 Answer 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])
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.