这个 努比。任何() 函数测试沿上述轴的任何数组元素的计算结果是否为真。 语法:
null
numpy.any(a, axis = None, out = None, keepdims = class numpy._globals._NoValue at 0x40ba726c)
参数:
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 AND 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 keepdmis : [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.
返回:
A new Boolean array as per 'out' parameter
代码1:
# 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 ( "Bool Value with axis = 0 : " , geek. any ([[ True , False ],[ True , True ]], axis = 0 )) print ( "Bool : " , 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 ( "Bool : " , geek. any ([ 1.0 , geek.nan])) print ( "Bool Value : " , geek. any ([[ 0 , 0 ],[ 0 , 0 ]])) |
输出:
Bool Value with axis = NONE : True Bool Value with axis = 0 : [ True True] Bool : True Bool : True Bool Value : False
代码2:
# Python Program illustrating # numpy.any() method # Parameter : keepdmis import numpy as geek # setting keepdmis = True print ( "Bool Value : " , geek. any ([[ 1 , 0 ],[ 0 , 4 ]], True )) # setting keepdmis = True print ( "Bool Value : " , geek. any ([[ 0 , 0 ],[ 0 , 0 ]], False )) |
输出:
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)
参考资料: https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.any.html#numpy.any
注: 这些代码不会在online-ID上运行。请在您的系统上运行它们以探索工作环境。 . 本文由 莫希特·古普塔(Mohit Gupta_OMG) .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。
如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END