My question is "why?:"
aa[0]
array([[405, 162, 414, 0,
array([list([1, 9, 2]), 18, (405, 18, 207), 64, 'Universal'],
dtype=object),
0, 0, 0]], dtype=object)
aaa
array([[405, 162, 414, 0,
array([list([1, 9, 2]), 18, (405, 18, 207), 64, 'Universal'],
dtype=object),
0, 0, 0]], dtype=object)
np.array_equal(aaa,aa[0])
False
Those arrays are completly identical.
My minimal example doesn't reproduce this:
be=np.array([1],dtype=object)
be
array([1], dtype=object)
ce=np.array([1],dtype=object)
ce
array([1], dtype=object)
np.array_equal(be,ce)
True
Nor does this one:
ce=np.array([np.array([1]),'5'],dtype=object)
be=np.array([np.array([1]),'5'],dtype=object)
np.array_equal(be,ce)
True
However, to reproduce my problem try this:
be=np.array([[405, 162, 414, 0, np.array([list([1, 9, 2]), 18, (405, 18, 207), 64, 'Universal'],dtype=object),0, 0, 0]], dtype=object)
ce=np.array([[405, 162, 414, 0, np.array([list([1, 9, 2]), 18, (405, 18, 207), 64, 'Universal'],dtype=object),0, 0, 0]], dtype=object)
np.array_equal(be,ce)
False
np.array_equal(be[0],ce[0])
False
And I have no idea why those are not equal. And to add the bonus question, how do I compare them?
I need an efficient way to check if aaa is in the stack aa.
I'm not using aaa in aa
because of DeprecationWarning: elementwise == comparison failed; this will raise an error in the future.
and because it still returns False
if anyone is wondering.
What else have I tried?:
np.equal(be,ce)
*** ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
np.all(be,ce)
*** TypeError: only integer scalar arrays can be converted to a scalar index
all(be,ce)
*** TypeError: all() takes exactly one argument (2 given)
all(be==ce)
*** TypeError: 'bool' object is not iterable
np.where(be==ce)
(array([], dtype=int64),)
And these, which I can't get to run in the console, all evaluate to False, some giving the deprecation warning:
import numpy as np
ce=np.array([[405, 162, 414, 0, np.array([list([1, 9, 2]), 18, (405, 18, 207), 64, 'Universal'],dtype=object),0, 0, 0]], dtype=object)
be=np.array([[405, 162, 414, 0, np.array([list([1, 9, 2]), 18, (405, 18, 207), 64, 'Universal'],dtype=object),0, 0, 0]], dtype=object)
print(np.any([bee in ce for bee in be]))
print(np.any([bee==cee for bee in be for cee in ce]))
print(np.all([bee in ce for bee in be]))
print(np.all([bee==cee for bee in be for cee in ce]))
And of course other questions telling me this should work...
See Question&Answers more detail:
os