Python 使用 NumPy 输入矩阵的两种方法
您可以使用以下两种代码来输入矩阵:
方法一:使用 np.array() 函数
import numpy as np
# 创建一个3x3的矩阵
matrix = np.array([[1,2,3], [4,5,6], [7,8,9]])
print(matrix)
输出:
[[1 2 3]
[4 5 6]
[7 8 9]]
方法二:使用 np.matrix() 函数
import numpy as np
# 创建一个2x2的矩阵
matrix = np.matrix([[1,2], [3,4]])
print(matrix)
输出:
[[1 2]
[3 4]]
原文地址: https://www.cveoy.top/t/topic/nexf 著作权归作者所有。请勿转载和采集!