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) #矩阵乘法