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


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

借助Numpy matrix.getfield()方法,我們可以獲得字段矩陣,這意味著field是具有給定數據類型的矩陣的視圖,該數據類型的大小與給定矩陣的大小相同。

用法: matrix.getfield()

返回: 返回場矩陣


範例1:
在此示例中,我們可以看到可以借助方法獲得字段矩陣matrix.getfield()

# import the important module in python 
import numpy as np 
          
# make matrix with numpy 
gfg = np.matrix('[6, 1; 2, 3]') 
          
# applying matrix.getfield() method 
geeks = gfg.getfield(int) 
    
print(geeks)
輸出:
[[6 1]
 [2 3]]

範例2:

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


相關用法


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