Re: [Numpy-discussion] Why are empty arrays False?
![](https://secure.gravatar.com/avatar/9bf244c487ed59f016d93ccf42929914.jpg?s=120&d=mm&r=g)
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.
![](https://secure.gravatar.com/avatar/209654202cde8ec709dee0a4d23c717d.jpg?s=120&d=mm&r=g)
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@gmail.com> wrote:
![](https://secure.gravatar.com/avatar/209654202cde8ec709dee0a4d23c717d.jpg?s=120&d=mm&r=g)
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@gmail.com> wrote:
participants (2)
-
Andrew Nelson
-
Eric Wieser