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?
1 Answer
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.
If the iterable is empty, return True.