📜  Python| numpy numpy.ndarray.__and__()

📅  最后修改于: 2022-05-13 01:54:44.674000             🧑  作者: Mango

Python| numpy numpy.ndarray.__and__()

Numpy numpy.ndarray.__and__()方法的帮助下,我们可以通过在numpy.ndarray numpy.ndarray.__and__()方法中作为参数提供的值来获取与元素进行与运算的元素。

示例 #1:
在这个例子中,我们可以看到每个元素都由作为ndarray.__and__()方法中的参数传递的值进行与运算。

# 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.__and__() method
print(gfg.__and__(2))
输出:
[0 2 2 0 0]

示例 #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.__and__() method
print(gfg.__and__(1))
输出:
[[1 0 1 0 1]
 [0 1 0 1 0]]