Overview:
-
The numpy.any() applies logical OR across the rows, columns or on the entire ndarray to check whether any of the elements in the given axis evaluate to True.
-
Applying numpy.any() results in the reduction of the ndarray. When the axis = None, the whole ndarray is reduced to single Boolean value-True or False.
-
The any() function differs from all(), that the all() reduces an ndarray using logical AND. The object oriented versions of these functions are compared with examples in the all() and any() methods of numpy.ndarray.
Example:
# Example Python program that uses any() method # Create an ndarray and fill with random Boolean values for i in range(0, 3): print("The ndarray:") # Apply any() - axis=0 |
Output:
The ndarray: [[1 1 0 0] [0 1 0 0] [0 0 1 0]] Results of any() row-wise: [ True True True] Results of any() column-wise: [ True True True False] |