numpy:向量 x 矩阵 x 向量乘法

numpy: vector x matrix x vector multiplication

如何在 numpy 中将多个向量和矩阵相乘,如下例所示:

# 1. vector
a = np.array([1, 2])
# matrix
b = np.array([[4, 0],[0, 5]])
# 2. vector
c = a.T

我想乘以 axbxc 并得到 24 作为结果。

使用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