The all()
function in Python is simply used to check if all the elements of an array along a given axis evaluate to True
.
numpy.all(a, axis=None, out=None, keepdims=<no value>, *, where=<no value>)
The all()
function takes a mandatory function a
which represents the input array or objects that can be converted to an array.
The all()
function takes the following optional parameter values:
axis
: The represents the axis or axes along which a logical AND
reduction is perfromed. 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 elements to include in checking for all True
values.The all()
function returns a boolean value or array.
import numpy as np# creating an arraymyarray = np.arange(6) + 1# calling the numpy.all() functionnewarray = np.all(myarray)# printing the arrayprint(newarray)
numpy
module.myarray
.all()
function on the array myarray
. The result is assigned to a new variable, newarray
.newarray
.