[英]numpy: vector x matrix x vector multiplication
How can I multiply the multiple vectors and matrix in numpy shown in example below:如何将 numpy 中的多个向量和矩阵相乘,如下例所示:
# 1. vector
a = np.array([1, 2])
# matrix
b = np.array([[4, 0],[0, 5]])
# 2. vector
c = a.T
I want to multiply axbxc and find the 24 as a result.我想将 axbxc 相乘并找到 24 作为结果。
Use numpy.matmul(a, b) as follows:使用 numpy.matmul(a, b) 如下:
import numpy as np
# 1. vector
a = np.array([1, 2])
# matrix
b = np.array([[4, 0],[0, 5]])
# 2. vector
c = a.T
# np.matmul gets 2 inputs which are matrix (1x2, 2x3 etc.) and returns result.
result = np.matmul(np.matmul(a,b), c)
print(result)
# 24
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.