Open thouis opened 12 years ago
Comment in Trac by atmention:charris, 2012-04-27
Strange indeed. This is going to be fun to figure out. My guess it that the first item is the same object in a and a.copy(), whereas it is a different object for the other array created with the same parameters... and it is so.
In [12]: b = np.array([np.array([0, 1]), np.array(1)], dtype=object)
In [13]: type b[1]
-------> type(b[1])
Out[13]: numpy.ndarray
In [14]: c = b.copy()
In [15]: c[0] is b[0]
Out[15]: True
In [16]: d = np.array([0,1])
In [17]: c[0] is d
Out[17]: False
So the comparison is comparing object pointers rather than calling a comparison routine. It's certainly easier to compare the pointers. I'm not sure if this is a bug or a feature ;) Shouldn't be hard to find where it happens.
Comment in Trac by atmention:charris, 2012-04-27
OTOH
In [37]: a = np.array([[257]*2, 257], dtype=object)
In [38]: b = np.array([[257]*2, 257], dtype=object)
In [39]: a == b
Out[39]: array([ True, True], dtype=bool)
In [40]: a[0] is b[0]
Out[40]: False
So it looks specific to arrays.
Original ticket http://projects.scipy.org/numpy/ticket/2117 Reported 2012-04-26 by atmention:yarikoptic, assigned to unknown.
This issue became more visible since 1.6.x allowed to construct such heterogeneous arrays without specification of dtype=object:
So -- comparing an object array to itself's copy worked just fine but comparison to identically created another one -- failed.