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


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

借助Numpy matrix.tolist()方法,我們可以通過使用將矩陣轉換為列表matrix.tolist()方法。

用法: matrix.tolist()
返回: Return a new list

範例1:
在此示例中,我們可以看到通過傳遞矩陣,我們可以將其轉換為列表matrix.tolist()方法。


# import the important module in python 
import numpy as np 
              
# make matrix with numpy 
gfg = np.matrix('[4, 1, 12, 3]') 
              
# applying matrix.tolist() method 
geek = gfg.tolist() 
    
print(geek)
輸出:
[[4, 1, 12, 3]]

範例2:

# import the important module in python 
import numpy as np 
              
# make matrix with numpy 
gfg = np.matrix('[4, 1, 9; 12, 3, 1; 4, 5, 6]') 
              
# applying matrix.tolist() method 
geek = gfg.tolist() 
    
print(geek)
輸出:
[[4, 1, 9], [12, 3, 1], [4, 5, 6]]


相關用法


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