Re: [Numpy-discussion] Why are empty arrays False?
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.
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
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@python.org https://mail.python.org/mailman/listinfo/numpy-discussion
participants (2)
-
Andrew Nelson
-
Eric Wieser