3

I noticed that numpy.all(np.array([])) evaluates to True. I could not find any documentation for this particular case. Is this an undefined behavior or is all guaranteed to evaluate to True for empty arrays?

2
  • 3
    The Python list equivalent notes: If the iterable is empty, return True. Commented May 7, 2017 at 1:35
  • You could submit a documentation patch to numpy. Commented May 7, 2017 at 4:49

1 Answer 1

2

NumPy is consistent with the logic of Python lists:

>>> all([])
True
>>> any([])
False

And both follow the rules of formal logic, which might mean there is no need to document this as a special case. Example: unicorns do not exist, so the list of unicorns is []

  • The statement "all unicorns are red" is true. It spells out as "if X is a unicorn, then X is red", which is true for all objects since they are not unicorns.
  • The statement "some unicorns are red" is false, because it asserts the existence of at least one red unicorn.

More on Wikipedia: Vacuous truth.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.