矩阵(一)
作者:互联网
numpy 创建矩阵,矩阵运算
import numpy as np
ary = np.arange(1, 10).reshape(3, 3)
print(ary, ary.shape, type(ary))
m1 = np.matrix(ary, copy=True) # copy控制是否拷贝一份数据,影响数据共享,默认True是拷贝,不共享,数据独立
print(m1, m1.dtype, m1.shape, type(m1))
m2 = np.mat(ary) # 默认copy = False,数据共享
print(m2, type(m2))
m3 = np.mat('1 2 3; 4 5 6') # ;分割维度,空格分割同纬度的数据 (多空几个空格也可以)
print(m3, type(m3))
print(ary * ary) #对应位置元素相乘
print(m1 * m1) #矩阵乘法
标签:ary,矩阵,np,m1,print,type 来源: https://blog.csdn.net/qq_45298704/article/details/120684593