[Numpy-discussion] "False" and "True" not singletons?
Pauli Virtanen
pav at iki.fi
Tue Dec 30 17:27:58 EST 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