3

In python, we usually check if an object is in an array by the in keyword, for example, this code:

a = [1, 2, 3]
print(4 in a)
b = np.array(a)
print(4 in a)

would give False, False.

However, I found that if I use 2d ndarray, the behavior is very weird, the following:

a = [[0,0], [0,1]]
print([0,2] in a)
b = np.array(a)
print([0,2] in b)

gives False, True.

What's going on here?

seekiu
  • 117
  • 1
  • 1
  • 6

0 Answers0