在数学上,我试图计算x^T A x,其中x是n维坐标,A是n维方阵.然而,我想高效地计算一组坐标的这个值.例如,在两个维度中:
import numpy as np
x = np.column_stack([[1,2,3,4,5],[6,7,8,9,0]])
A = np.array([[1,0],[0,2]])
print(x[0] @ A @ x[0]) # works
# How can I get efficiently an array of x[i] @ A @ x[i]?
y = [x[i] @ A @ x[i] for i in range(x.shape[0])]