[Numpy-discussion] Why are empty arrays False?
wieser.eric+numpy at gmail.com
Sat Aug 19 05:00:43 EDT 2017
Andrew, that can only be useful if you also require that all non-empty
arrays are True - else code looking for empty arrays gets false positives
on arrays of zeros.
But as I mention above, that is not acceptable, as it produces silent traps
for new users, or functions not written with numpy in mind. "In the face of
ambiguity, refuse the tempting to guess" tells us that throwing an error is
the right thing to do here.
In idiomatic code, numpy arrays have semantics closer to scalars than to
sequences - iteration is usually a red flag. Another example of how arrays
are not like sequences - the + operator is element-wise addition, not
On Sat, Aug 19, 2017, 15:58 Andrew Nelson <andyfaff at gmail.com> wrote:
> > I think the consistency between bool() and
> bool(array()) is worth preserving
> I'm with Eric Firing on this one. Empty sequences are False in Python.
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion