I want to perform the following Weighted least square operation:
L = ((x^t * W * x)^-1)(X^t *W*y)
Where x is(240, 60) matrix
y is (240, 1) matrix
W is diagonal matrix of shape (60, 60)
I tried to implement the first part before calculation the inverse x^t * W * x as following:
np.dot(x.transpose(),W,x)
i got the error:
shapes (60,240) and (60,240) not aligned: 240 (dim 1) != 60 (dim 0)
Also implementing
numpy.transpose(x)*W*y
gives the error
operands could not be broadcast together with shapes (60,240) (240,1)
What would be the best way to complete the multiplication ? I want then to implements the SVD method to get the inverse of the term (x^t * W * x)
CodePudding user response:
import numpy as numpy
x = numpy.random.random((240, 60))
y = numpy.random.random((240, 1))
W = numpy.random.random((60, 60))
second_part = numpy.dot(numpy.transpose(numpy.dot(x,W)),y)
CodePudding user response:
In python, ^
( the pow operation ) is changed to **
but dont be confused with **kwargs
.