📜  Python| numpy numpy.matrix.any()

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

Python| numpy numpy.matrix.any()

Numpy numpy.matrix.any()方法的帮助下,我们能够将一个矩阵的每个元素与另一个矩阵进行比较,或者如果任何元素匹配,我们可以提供我们想要应用比较的轴返回 true .

示例 #1:
在这个例子中,我们可以看到在matrix.any()方法的帮助下,我们可以比较任意两个具有不同维度的矩阵,如果找到任何匹配项,则返回 true。

# import the important module in python
import numpy as np
          
# make a matrix with numpy
gfg1 = np.matrix('[1, 2, 3, 4]')
gfg2 = np.matrix('[1, 2]')
          
# applying matrix.any() method
geeks = (gfg1 == gfg2).any()
    
print(geeks)
输出:
True

示例 #2:

# import the important module in python
import numpy as np
          
# make a matrix with numpy
gfg1 = np.matrix('[1, 2, 3; 4, 5, 6; 7, 8, 9]')
gfg2 = np.matrix('[1, 2, 3]')
          
# applying matrix.any() method
geeks = (gfg1 == gfg2).any()
    
print(geeks)
输出:
True