Is there an “enhanced” numpy/scipy dot method?

前端 未结 3 1194
温柔的废话
温柔的废话 2020-12-24 12:45

Problem

I would like to compute the following using numpy or scipy:

Y = A**T * Q * A

where A is a m x n ma

3条回答
  •  独厮守ぢ
    2020-12-24 13:08

    numpy.einsum is what you're looking for:

    numpy.einsum('ij, i, ik -> jk', A, Q, A)
    

    This shall not need any additional memory (though usually einsum works slowlier than BLAS operations)

提交回复
热议问题