[Numpy-discussion] fastest way to do multiplication with diagonal matrices from left or right
Mon Mar 26 12:00:55 CDT 2007
> Dear list
> what is the fastet way to multiply with a diagonal matrix from left or
> right and without to build a square matrix from the diagonal.
Use broadcasting to do your work for you.
from numpy import array, newaxis
diags = array([...])
mymatrix = array([[...]])
# From the right:
mymatrix * diags
# From the left:
diags[:,newaxis] * mymatrix
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Numpy-discussion