[Numpy-discussion] Puzzling numpy results?
Andrew McNamara
andrewm at object-craft.com.au
Sun Apr 7 23:32:07 CDT 2002
The behavior I'm seeing with zero length Numeric arrays is not what I
would have expected:
>>> from Numeric import *
>>> array([5]) != array([])
zeros((0,), 'l')
>>> array([]) == array([])
zeros((0,), 'l')
>>> allclose(array([5]), array([]))
1
This is with Numeric-20.3 (and Numeric-20.2.1) - is this behavior correct,
or have I stumbled across a bug?
If both sides of the comparison are arrays with a length greater than
zero, the comparisons work as expected:
>>> array([5]) != array([6])
array([1])
>>> array([5, 5]) != array([6])
array([1, 1])
>>> array([5]) != array([5])
array([0])
The problem came up when I was writing unittests for some Numpy code:
under some circumstances, the code under test is expected to return a
zero length array: I was somewhat surprised when I couldn't make the
test fail! 8-)
--
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/
More information about the Numpy-discussion
mailing list