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


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

借助Numpy matrix.put()方法,我們可以通過將索引和值傳遞到給定的矩陣中來放置值。

用法: matrix.put(index, value)

返回: 返回新矩陣


範例1:
在這個例子中,我們可以看到我們可以借助方法將給定矩陣中的值matrix.put()

# import the important module in python 
import numpy as np 
          
# make matrix with numpy 
gfg = np.matrix('[64, 1; 12, 3]') 
          
# applying matrix.put() method 
gfg.put((0, 1), 45) 
    
print(gfg)
輸出:
[[45 45]
 [12  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.put() method 
gfg.put(2, 43) 
    
print(gfg)
輸出:
[[ 1  2 43]
 [ 4  5  6]
 [ 7  8 -9]]


相關用法


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