any() and all() are intended for boolean arrays. any() returns True if there's any values that are equal to True in the array. all() returns True if all values in the array are equal to True. For integers/floats the functionality is similar, except that they return True if the value 0 is not found in the array. In your example, since both a.any() and a.all() will return True, it follows that a.any() == a.all().

Try executing the following code to see how it works in practice.

a = np.asarray([1,2,3])
b = np.asarray([-1,0,1])
c = np.asarray([True, False])

print(a.any())
print(a.all())

print(b.any())
print(b.all())

print(c.any())
print(c.all())
Answer from user2653663 on Stack Overflow
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.any.html
numpy.any — NumPy v2.5 Manual
Not a Number (NaN), positive infinity and negative infinity evaluate to True because these are not equal to zero. Changed in version 2.0: Before NumPy 2.0, any did not return booleans for object dtype input arrays.
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-any-in-python
numpy.any() in Python - GeeksforGeeks
March 7, 2024 - If the sub-classes sum method does not implement keepdims any exceptions will be raised. ... # Python Program illustrating # numpy.any() method import numpy as geek # Axis = NULL # True False # True True # True : False = True (OR) print("Bool Value with axis = NONE : ", geek.any([[True,False],[True,True]])) # Axis = 0 # True False # True True # True : False print("\nBool Value with axis = 0 : ", geek.any([[True,False],[True,True]], axis = 0)) print("\nBool : ", geek.any([-1, 4, 5])) # Not a Number (NaN), positive infinity and negative infinity # evaluate to True because these are not equal to zero.
🌐
YouTube
youtube.com › watch
NumPy np.any() Tutorial - Master Array Validation in Python | Beginner Friendly - YouTube
🔍 Learn how to use NumPy's np.any() function for efficient array validation in Python! This beginner-friendly tutorial covers everything you need to know ab...
Published   October 29, 2025
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.ndarray.any.html
numpy.ndarray.any — NumPy v2.5 Manual
Returns True if any of the elements of a evaluate to True. Refer to numpy.any for full documentation.
Find elsewhere
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.all.html
numpy.all — NumPy v2.1 Manual
Axis or axes along which a logical AND reduction is performed. The default (axis=None) is to perform a logical AND over all the dimensions of the input array.
🌐
NumPy
numpy.org › doc › 2.4 › reference › generated › numpy.any.html
numpy.any — NumPy v2.4 Manual
Not a Number (NaN), positive infinity and negative infinity evaluate to True because these are not equal to zero. Changed in version 2.0: Before NumPy 2.0, any did not return booleans for object dtype input arrays.
🌐
JAX Documentation
docs.jax.dev › en › latest › _autosummary › jax.numpy.any.html
jax.numpy.any — JAX documentation
Test whether any of the array elements along a given axis evaluate to True. JAX implementation of numpy.any().
🌐
Python Tutorial
pythontutorial.net › home › python numpy › numpy any()
NumPy any()
August 10, 2022 - The numpy any() function returns True if any element in an array (or along a given axis) evaluates to True.
🌐
SciPy
docs.scipy.org › doc › › numpy-1.6.0 › reference › generated › numpy.any.html
numpy.any — NumPy v1.6 Manual (DRAFT)
May 15, 2011 - Numpy and Scipy Documentation » · NumPy Reference » · Routines » · Logic functions » · numpy.any(a, axis=None, out=None)¶ · Test whether any array element along a given axis evaluates to True. Returns single boolean unless axis is not None · See also · ndarray.any ·
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ndarray.any.html
numpy.ndarray.any — NumPy v2.1 Manual
Returns True if any of the elements of a evaluate to True. Refer to numpy.any for full documentation.
🌐
Reddit
reddit.com › r/learnpython › when do you get use np.any()/np.all() error instead of returning array of booleans?
r/learnpython on Reddit: When do you get use np.any()/np.all() error instead of returning array of Booleans?
May 11, 2024 -

Say I have two np arrays of the same size in, a and b. Sometimes writing something like print(a == b) gives an array like [True True False True ...] going through and pairing each element, but sometimes I get an error saying use a.any() or a.all(). I can't figure out the rationale behind when I get each result.

Top answer
1 of 2
3
This is there to flag up a common gotcha that might otherwise exist. In python, commonly you check the truth value of various things. Eg. you might check if x == 42: to see if x is equal to 42. However, numpy overrides the way == works. Instead of checking if the whole array is equal to the value 42, it does a piecewise comparison and returns a new array of booleans that is true where the corresponding member equalled 42. And this is very useful for a numpy workflow. However, going back to if x == 42:, it means we're now checking if (big array of booleans):. So what should the truth value of a big array of booleans, some true, some false, be? Maybe you wanted to check if all the values were true. Maybe you wanted to check if any value was true. Maybe you expected it to be true if non-empty, like python lists. Maybe something else. Ultimately, the answer is ambiguous at best, and so numpy doesn't try to guess, but instead raises an error any time you're trying to convert an array to a bool (with those suggesetions for what it thinks you might have wanted). This is going to happen implicitly in things like if and while blocks, which is likely where you're seeing the error.
2 of 2
2
You get the error when there's a cast to a boolean (even implicit) - which usually means when you use it in an if statement. Example: import numpy as np arr1=np.array([1,2,3]) arr2=np.array([1,2,5]) print(arr1==arr2) # Fine print(bool(arr1 == arr2)) # not Fine if bool(arr1 == arr2): # Not fine, explicit cast to boolean print("yar") if arr1 == arr2: # Not fine, implicit cast to boolean, same as above print("yar") if (arr1 == arr2).all(): # fine print('yar') if (arr1 == arr2).any(): # fine print('yar') Note that having arr1 == arr2 and arr1 == value result in an array is very useful. It allows things like using arr1[arr1==0] = 1 to replace all 0s in an array with 1. But numpy doesn't want to have a way to covert that array to a single boolean. So they don't.
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.ndarray.any.html
numpy.ndarray.any — NumPy v2.3 Manual
Returns True if any of the elements of a evaluate to True. Refer to numpy.any for full documentation.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.any.html
numpy.any — NumPy v2.1 Manual
Not a Number (NaN), positive infinity and negative infinity evaluate to True because these are not equal to zero. Changed in version 2.0: Before NumPy 2.0, any did not return booleans for object dtype input arrays.
🌐
Codecademy
codecademy.com › docs › python:numpy › ndarray › any()
Python:NumPy | ndarray | any() | Codecademy
October 31, 2025 - The any() method of a NumPy ndarray returns True if at least one element in the array evaluates to True. It performs a logical OR operation across specified array elements.
🌐
Educative
educative.io › answers › what-is-the-numpyany-function-in-numpy
What is the numpy.any() function in NumPy?
The any() function in NumPy is used to check if all the elements of an array along a given axis evaluate to True.
🌐
GitHub
github.com › numpy › numpy › issues › 26197
BUG: numpy.any returns True given a boolean array of all False with the intel compiler · Issue #26197 · numpy/numpy
April 2, 2024 - However, if the length is 64 or more, np.any returns True. import numpy as np Y = np.zeros(63, bool) ; print(np.any(Y)) # prints "False", as expected Y = np.zeros(64, bool) ; print(np.any(Y)) # prints "True"
Author   numpy
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.any.html
numpy.any — NumPy v2.6.dev0 Manual
Not a Number (NaN), positive infinity and negative infinity evaluate to True because these are not equal to zero. Changed in version 2.0: Before NumPy 2.0, any did not return booleans for object dtype input arrays.
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.ndarray.any.html
numpy.ndarray.any — NumPy v2.6.dev0 Manual
Returns True if any of the elements of a evaluate to True. Refer to numpy.any for full documentation.