当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python Numpy numpy.ndarray.__or__()用法及代码示例


借助Numpy numpy.ndarray.__or__()方法,我们可以通过作为参数提供的值来获得OR元素numpy.ndarray.__or__()方法。

用法:ndarray.__or__($self, value, /)

返回:self|value


范例1:
在此示例中,我们可以看到每个元素都是或通过作为参数传递给ndarray.__or__()方法。

# import the important module in python 
import numpy as np 
     
# make an array with numpy 
gfg = np.array([1, 2, 3, 4, 5]) 
     
# applying ndarray.__or__() method 
print(gfg.__or__(2))
输出:
[3 2 3 6 7]

范例2:

# import the important module in python 
import numpy as np 
     
# make an array with numpy 
gfg = np.array([[1, 2, 3, 4, 5], 
                [6, 5, 4, 3, 2]]) 
     
# applying ndarray.__or__() method 
print(gfg.__or__(1))
输出:
[[1 3 3 5 5]
 [7 5 5 3 3]]


相关用法


注:本文由纯净天空筛选整理自Jitender_1998大神的英文原创作品 Python | Numpy numpy.ndarray.__or__()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。