The any()
function in NumPy is used to check if all the elements of an array along a given axis evaluate to True
.
numpy.any(a, axis=None, out=None, keepdims=<no value>, *, where=<no value>)
The any()
function takes a mandatory parameter, a
, which represents the input array or collection of objects that can be converted to an array.
The any()
function takes the following optional parameter values:
axis
: This represents the axis or axes along which a logical AND
reduction operation is performed. The default value is (axis = None
) and when negative, it counts from the last to the first axis.out
: This represents an alternate output array in which to place to the result. It must have the same shape as the expected output array.keepdims
: If this is set to True
, axes which are reduced are left in the result as dimensions with size one.where
: This represents choice of elements to check for any True
values.The any()
function returns a boolean value or array.
import numpy as np# creating an arraymy_array = np.arange(6) + 1# calling the any() functionnew_array = np.any(my_array)# printing the arrayprint(new_array)
numpy
module.my_array
.any()
function on the array my_array
. The result is assigned to a new variable new_array
.new_array
.