[Numpy-discussion] numarray equality testing

Perry Greenfield perry at stsci.edu
Mon Dec 9 07:40:04 EST 2002

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))
>>> array_equal(array([1,2,3]), array([1,2,0]))
>>> array_equal( arange(2), None )
>>> array_equal( arange(2), not_an_ndarray_instance)
>>> array_equal(array([[1,2,3],[1,2,3]]), array([1,2,3]))


Perry Greenfield

More information about the NumPy-Discussion mailing list