Hi,
There is some unexpected behaviour (to me) when 0dimensional arrays are compared with values. For example:
numpy.array([0]).squeeze() == 0
True
numpy.array([None]).squeeze() == None
False
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 workable.
Are these the intended results?
Thanks, Tom

Thomas J. Duck tom.duck@dal.ca
Associate Professor, Department of Physics and Atmospheric Science, Dalhousie University, Halifax, Nova Scotia, Canada, B3H 3J5. Tel: (902)4941456  Fax: (902)4945191  Lab: (902)4943813 Web: http://aolab.phys.dal.ca/
2008/7/25 Thomas J. Duck tom.duck@dal.ca:
Hi,
There is some unexpected behaviour (to me) when 0dimensional
arrays are compared with values. For example:
numpy.array([0]).squeeze() == 0
True
numpy.array([None]).squeeze() == None
False
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 workable.
Are these the intended results?
I would think not. E.g., in the following case broadcasting should kick in:
In [20]: np.array([None, None, None]) == None Out[20]: False
In [21]: np.array([None, None, None]) == [None] Out[21]: array([ True, True, True], dtype=bool)
Cheers Stéfan
On Fri, Jul 25, 2008 at 19:19, Stéfan van der Walt stefan@sun.ac.za wrote:
2008/7/25 Thomas J. Duck tom.duck@dal.ca:
Hi,
There is some unexpected behaviour (to me) when 0dimensional
arrays are compared with values. For example:
numpy.array([0]).squeeze() == 0
True
numpy.array([None]).squeeze() == None
False
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 workable.
Are these the intended results?
I would think not. E.g., in the following case broadcasting should kick in:
In [20]: np.array([None, None, None]) == None Out[20]: 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.
participants (3)

Robert Kern

Stéfan van der Walt

Thomas J. Duck