The numpy.any() function tests whether any array elements along the mentioned axis evaluate to True. Syntax :
numpy.any(a,
axis = None,
out = None,
keepdims = class numpy._globals._NoValue at 0x40ba726c)
Parameters :
array :[array_like]Input array or object whose elements, we need to test.
axis : [int or tuple of ints, optional]Axis along which array elements
are evaluated.
The default (axis = None) is to perform a logical OR over all the dimensions of the input
array. Axis may be negative, in which case it counts from the last to the first axis.
out : [ndarray, optional]Output array with same dimensions as Input array,
placed with result
keepdims : [boolean, optional]If this is set to True, the axes which are
reduced are left in the result as dimensions with size one. With this option, the result
will broadcast correctly against the input array.
If the default value is passed, then keepdims will not be passed through to the all
method of sub-classes of ndarray, however any non-default value will be. If the
sub-classes sum method does not implement keepdims any exceptions will be raised.
Return :
A new Boolean array as per 'out' parameter
Code 1 :
Python
# 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.
print("\nBool : ", geek.any([1.0, geek.nan]))
print("\nBool Value : ", geek.any([[0, 0],[0, 0]]))
Output :
Bool Value with axis = NONE : True
Bool Value with axis = 0 : [ True True]
Bool : True
Bool : True
Bool Value : False
Code 2 :
Python
# Python Program illustrating
# numpy.any() method
# Parameter : keepdmis
import numpy as geek
# setting keepdmis = True
print("\nBool Value : ", geek.any([[1, 0],[0, 4]], True))
# setting keepdmis = True
print("\nBool Value : ", geek.any([[0, 0],[0, 0]], False))
Output :
Bool Value : [ True True]
Bool Value : [False False]
VisibleDeprecationWarning: using a boolean instead of an integer
will result in an error in the future
return umr_any(a, axis, dtype, out, keepdims)
Note : These codes won't run on online IDE's. So please, run them on your systems to explore the working.
Similar Reads
numpy.all() in Python The numpy.all() function tests whether all array elements along the mentioned axis evaluate to True. Syntax: numpy.all(array, axis = None, out = None, keepdims = class numpy._globals._NoValue at 0x40ba726c) Parameters :Â array :[array_like]Input array or object whose elements, we need to test. axis
3 min read
numpy.isnan() in Python The numpy.isnan() function tests element-wise whether it is NaN or not and returns the result as a boolean array. Syntax :Â numpy.isnan(array [, out]) Parameters :Â array : [array_like]Input array or object whose elements, we need to test for infinity out : [ndarray, optional]Output array placed wit
2 min read
Python | Numpy numpy.matrix.any() With the help of Numpy numpy.matrix.any() method, we are able to compare each and every element of one matrix with another or we can provide the axis on the we want to apply comparison if any of the element matches it return true. Syntax : numpy.matrix.any() Return : Return true if any match found e
1 min read
numpy.isfinite() in Python The numpy.isfinite() function tests element-wise whether it is finite or not(not infinity or not Not a Number) and return the result as a boolean array. Syntax :Â numpy.isfinite(array [, out]) Parameters :Â array : [array_like]Input array or object whose elements, we need to test for infinity out :
2 min read
numpy.isreal() in Python numpy.isreal() tests element-wise whether each value in the input array is a real number (i.e., not complex). It returns a Boolean result as a boolean array. Example:Pythonimport numpy as np a = np.array([1+0j, 2+3j, 5, 4.5, 7j]) res = np.isreal(a) print(res)Output[ True False True True False] Expla
2 min read