
python设计矩阵:
1、调用numpy模块创建矩阵并设置矩阵的行跟列
import numpy matrix = numpy.array([[1,2,3],[4,5,6],[7,8,9]])#创建矩阵
2、通过下标的办法输出二维列表中的一维列表,达到输出矩阵的效果
vector = numpy.array([[1,2,3],[4,5,6],[7,8,9]]) print(vector) print(vector[0:3,0])#打印第一至三行,第一列 print(vector[2,2])#第三行第三列 print(vector[:,0])#只有一个冒号代表整行或整列
输出结果如下:
