0

I have a set of data that consists of over 1000 data points and each has 7 features. Basically, a (1000, 7) shaped data. By using it's covariance matrix, I want to calculate

X * Covariance * X and I want the result to be a size of (1000,)

If I do a loop over all X one by one, I can reach this result but is there a way that I can do using this data set as a whole? I am using numpy only.

X.T.dot(np.linalg.inv(covariance)).dot(X)

This is what I have right now. As I said I can do it by looping over all the X's but I want to do it without the loop. Is it possible? If so, how?

madml
  • 1
  • Check at this [post](https://stackoverflow.com/questions/21562986/numpy-matrix-vector-multiplication) – Ptit Xav Dec 01 '21 at 11:01

1 Answers1

0

You can do an Einstein summation

np.einsum('ij,jk,kl->il', X, np.linalg.inv(covariance),X )
Learning is a mess
  • 7,479
  • 7
  • 35
  • 71