With the following arrays of objects:
a = np.array([[1], [1, 2], [1, 2, 3], [1], [1]], dtype=object)
b = np.array([(1,), (1, 2), (1, 2, 3), (1,), (1,)], dtype=object)
The following equality checks do not work:
a==[1]
#array([False, False, False, False, False], dtype=bool)
b==(1,)
#array([False, False, False, False, False], dtype=bool)
if I use strings instead:
c = np.array(['[1]', '[1, 2]', '[1, 2, 3]', '[1]', '[1]'])
the equality check works:
c == '[1]'
#array([ True, False, False, True, True], dtype=bool)
why the array check behaves like that?
If we iterate over a or b and perform the checks it also gives the expected result:
[i==[1] for i in a]
#[True, False, False, True, True]
[i==(1,) for i in b]
#[True, False, False, True, True]
Thank you!