[Numpy-discussion] 0d array value comparisons
Fri Jul 25 21:41:29 CDT 2008
On Fri, Jul 25, 2008 at 19:19, Stéfan van der Walt <firstname.lastname@example.org> wrote:
> 2008/7/25 Thomas J. Duck <email@example.com>:
>> There is some unexpected behaviour (to me) when 0-dimensional
>> arrays are compared with values. For example:
>> >>> numpy.array().squeeze() == 0
>> >>> numpy.array([None]).squeeze() == None
>> >>> numpy.array(['a']).squeeze() == 'a'
>> array(True, dtype=bool)
>> Note that each test follows the same pattern, although the dtype for
>> each squeezed array is different. The first case result is what I
>> expected, and the second case result appears wrong. The return type
>> for the third case is inconsistent with those before, but is at least
>> Are these the intended results?
> I would think not. E.g., in the following case broadcasting should kick in:
> In : np.array([None, None, None]) == None
> Out: False
(some_ndarray == None) == False is actually an intentional special
case. I forget the details of why, and I don't feel like reinstalling
Numeric or numarray to see if it was backwards compatibility, but it's
not a bug.
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the Numpy-discussion