It dates back to Numeric's semantics for bool(some_array), which would
be True if any of the elements were nonzero. Just like any other
iterable container in Python, x in y
will essentially do
for row in y:
if x == row:
return True
return False
Iterate along the first axis of y and compare by boolean equality. In
Numeric/numpy's case, this comparison is broadcasted. So that's why
[3,6,4] works, because there is one row where 3 is in the first
column. [4,2,345] doesn't work because the 4 and the 2 are not in
those columns.
Probably, this should be considered a mistake during the transition to
numpy's semantics of having bool(some_array) raise an exception.
scalar in array
should probably work as-is for an ND array, but
there are several different possible semantics for array in array
that should be explicitly spelled out, much like bool(some_array).
m3 = [[1, 2, 3], [5, 4, 3]]
替换为m3 = [[1, 2, 3], [5, 3, 4]]
。 - Bi Rico