[Numpy-discussion] "False" and "True" not singletons?

Pauli Virtanen pav@iki...
Tue Dec 30 16:27:58 CST 2008


Tue, 30 Dec 2008 14:17:30 -0800, Christopher Barker wrote:

> Robert Kern wrote:
>> Well, True and False are singletons,
> 
> I thought so.
> 
>> but numpy.any() and numpy.all()
>> don't return bools. They return numpy.bool_s.
> 
> Is that a numpy scalar type?
> 
> This also begs the question: why don't they return regular old True and
> False?

Genericity. np.all and np.any take an axis parameter and usually return 
ndarrays; the default value, axis=None, is a corner case. Returning array 
scalars (which mostly quack like ndarrays) allows one to avoid the need 
for special-casing any subsequent code for axis=None.

-- 
Pauli Virtanen



More information about the Numpy-discussion mailing list