# Np.array([1,0]) in np.array([[1,1]]) == True?

Is this a bug?

``````In [31]: np.array([1,0]) in np.array([[1,1]])
Out[31]: True

``````

or, by parts

``````In [33]: a = np.array([[0,0]])

In [34]: b = np.array([1,0])

In [35]: b in a
Out[35]: True

``````

According to this reply the `in` operator is meaningful only if the first operand is scalar:

Another interesting question:

2 Likes

Unfortunate, but thanks

Out of curiosity, what is the source data? That is, what do these return?

``````print(np.array([1,0]))

print(np.array([[1,1]]))
``````
1 Like

None really, I was just learning the syntax, thus:

``````In [3]: print(np.array([1,0]))
[1 0]

In [4]: print(np.array([[1,1]]))
[[1 1]]

``````

by the way, it is also slightly confusing that the output format of the array is not consistent with the input:

``````In [5]: a = np.array([[0, 0]])

In [6]: for v in a :
...:     print(v)
...:
[0 0]

In [7]: [0 0] in a
File "<ipython-input-7-86c19ca29a5c>", line 1
[0 0] in a
^
SyntaxError: invalid syntax

``````

Try `repr()`. I am not sure how it is implemented in NumPy arrays but it is designed to get a consistent representation of objects.

``````for v in a:
print(repr(v))
print(f'{v!r}')    # shorthand for repr() inside formatted string
``````
2 Likes