當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Numpy numpy.matrix.all()用法及代碼示例

借助Numpy numpy.matrix.all()方法,我們可以將一個矩陣的每個元素與另一個矩陣進行比較,或者可以在要應用比較的軸上提供軸。

用法: numpy.matrix.all()

返回: 如果找到匹配則返回true,否則返回false


範例1:
在此示例中,我們可以借助matrix.all()方法,我們能夠比較任何兩個具有不同維度的矩陣。

# 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, 3, 4]') 
          
# applying matrix.all() method 
geeks = (gfg1 == gfg2).all() 
    
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.all() method 
geeks = (gfg1 == gfg2).all() 
    
print(geeks)
輸出:
False


相關用法


注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 Python | Numpy numpy.matrix.all()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。