This is a Numeric/numarray compatibility question. Numeric currently allows the equals ufunc to compare arrays of unequal sizes and returns a scalar 0 in such cases. When arrays have consistent shapes, an array of ints is returned. We argue that this is inconsistent with normal ufunc behavior and that it should generate an exception as do all non-equality ufuncs. (numarray currently does not allow comparison of shape-inconsistent arrays including for equality). Instead we propose a function whose purpose is to determine if two arrays are shape consistent (i.e., can be broadcast against each other) and have all values equal to each other.
array_equal(arange(2), arange(4)) 0 array_equal(array([1,2,3]), array([1,2,0])) 0 array_equal( arange(2), None ) 0 array_equal( arange(2), not_an_ndarray_instance) 0 array_equal(array([[1,2,3],[1,2,3]]), array([1,2,3])) 1
Comments? Perry Greenfield
On Mon, 9 Dec 2002, Perry Greenfield wrote:
array_equal(array([[1,2,3],[1,2,3]]), array([1,2,3])) 1
Hmm, I would have expected 0. What's the rationale for 1? May be you meant
array_equal(array([[1,2,3]]), array([1,2,3])) 1
which I would agree. Also
array_equal(array([[1],[2],[3]]), array([1,2,3])) 1
but I am not sure about
array_equal(array([[1,2,3],[1,2,3]]), array([1,2,3,1,2,3])) 1
Pearu
Pearu Peterson write:
On Mon, 9 Dec 2002, Perry Greenfield wrote:
array_equal(array([[1,2,3],[1,2,3]]), array([1,2,3])) 1
Hmm, I would have expected 0. What's the rationale for 1?
Because the arrays can be broadcast into a consistent array. In other words equals(array([[1,2,3],[1,2,3]]), array([1,2,3]) returns array([[1,1,1],[1,1,1]]) But I take your meaning. There may be those that wish to ensure that two arrays are really identical in shape and have all equal values. Should these be two different functions? One function with different options. By the way, I'm open to better function names as Tim Hochberg suggests.
May be you meant
array_equal(array([[1,2,3]]), array([1,2,3])) 1
which I would agree. Also
array_equal(array([[1],[2],[3]]), array([1,2,3])) 1
but I am not sure about
array_equal(array([[1,2,3],[1,2,3]]), array([1,2,3,1,2,3])) 1
Pearu
Perry
"Perry Greenfield"
Instead we propose a function whose purpose is to determine if two arrays are shape consistent (i.e., can be broadcast against each other) and have all values equal to each other.
So there would be that operation, plus one that checks identity of shape and all elements? That should cover all needs I can think of. Konrad.
participants (3)
-
Konrad Hinsen
-
Pearu Peterson
-
Perry Greenfield