📜  Python| numpy numpy.ndarray.__xor__()

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

Python| numpy numpy.ndarray.__xor__()

Numpy numpy.ndarray.__xor__()方法的帮助下,我们可以通过在numpy.ndarray.__xor__()方法中作为参数提供的值来获得异或的元素。

示例 #1:
在这个例子中,我们可以看到每个元素都是通过在ndarray.__xor__()方法中作为参数传递的值来异或的。

# 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.__xor__() method
print(gfg.__xor__(2))
输出:
[3 0 1 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.__xor__() method
print(gfg.__xor__(1))
输出:
[[0 3 2 5 4]
 [7 4 5 2 3]]