python数组、矩阵相乘的多种方式

1. numpy.ndarray类型乘积

1.1 矩阵乘法

a@b

np.dot(a, b)

np.matmul(a, b)

1.2 对应位置元素相乘

a*b

np.multiply(a, b)

2.numpy.matrix类型乘积

2.1 矩阵乘法

a@b

a*b

np.dot(a,b)

np.matmul(a,b)

2.2 对应位置元素相乘

np.multiply(a,b)

3.torch.tensor类型乘积

3.1 矩阵乘法

torch.mm(a,b) == a.mm(b) # 不广播,a、b必须都是二维张量
torch.matmul(a,b) == a.matmul(b) #广播,a、b可能是一维张量、二维张量、多维张量,功能特别多

1.2 对应位置元素相乘

a*b

torch.mul(a,b) == a.mul(b)