[Numpy-discussion] Why are empty arrays False?

Eric Wieser 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
sequence concatenation.

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
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20170819/1f3db5a3/attachment.html>


More information about the NumPy-Discussion mailing list