📜  Python| numpy matrix.tolist()

📅  最后修改于: 2022-05-13 01:54:22.495000             🧑  作者: Mango

Python| numpy matrix.tolist()

借助Numpy matrix.tolist()方法,我们可以使用matrix.tolist()方法将矩阵转换为列表。

示例 #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]]