numpy array 相乘和mat相乘的区别

numpy array相乘和mat相乘的区别

import numpy as np

if __name__ == '__main__':
    # np.array 相乘
    a = np.array([[1,2],[3,4]])
    b = np.array([[5,6],[7,8]])
    print(a*b)
    # np.mat相乘,即矩阵相乘
    a = np.mat(a)
    b = np.mat(b)
    print(a*b)

ans:

[[ 5 12]
 [21 32]]
[[19 22]
 [43 50]]
文章目录