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


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

借助Numpy matrix.fill()方法,我們可以填寫scalar value在給定的矩陣中給出並輸出為具有標量值的矩陣。

用法: matrix.fill(value)

返回: 返回具有標量值的矩陣


範例1:
在此示例中,我們可以借助matrix.fill()方法,我們可以用標量值填充給定矩陣。

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

範例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]') 
         
# applying matrix.fill() method 
gfg.fill(1) 
   
print(gfg)
輸出:
[[1 1 1]
 [1 1 1]]


相關用法


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