Why y=np.mat(y) in closed form solution?

In the closed form solution video , prateek bhaiya did y=np.mat(y) inorder to get the correct answer what was the reason for doing that ?

Hi,
Earlier Y was a column vector, and for finding the inverse it was required to have a matrix.
So np.mat() changed the data type from column vector to matrix. see the datatype when you use np.mat()

Sorry , but i am not able to understand why we only changed y to a matrix , x is also np.ndarray and why it is important to convert y from a column vector to a matrix to compute inverse ?

Parameters of pinv() :
a : (…, M, N) array_like
Matrix or stack of matrices to be pseudo-inverted.

so, it required a matrix to compute the inverse, column vector is not a matrix.
Therefore converted the column vector into matrix first.

whereas, X is array_like having shape (M,2) therefore, it acts as a ndarray or we can say matrix.
it is not a column or row vector .

1 Like

I think what you said did not really answered the question, instead the answer should be since we use * to multiply np.linalg.pinv(first) and second we get hadamard multiplication ( because both of them are np.ndarray ) instead of matrix multiplication. So , we can resolve this issue by
1. make y as a np.mat
2. Make x as np.mat
3. Take np.dot between np.linalg.pinv(first) and second.