[Numpy-discussion] matrix default to column vector?
Tom K.
tpk at kraussfamily.org
Sun Jun 14 12:20:51 EDT 2009
jseabold wrote:
>
> On Mon, Jun 8, 2009 at 3:33 PM, Robert Kern<robert.kern at gmail.com> wrote:
>> On Mon, Jun 8, 2009 at 14:10, Alan G Isaac<aisaac at american.edu> wrote:
>>>>> Going back to Alan Isaac's example:
>>>>> 1) beta = (X.T*X).I * X.T * Y
>>>>> 2) beta = np.dot(np.dot(la.inv(np.dot(X.T,X)),X.T),Y)
>>>
>>>
>>> Robert Kern wrote:
>>>> 4) beta = la.lstsq(X, Y)[0]
>>>>
>>>> I really hate that example.
>
I propose the following alternative for discussion:
U, s, Vh = np.linalg.svd(X, full_matrices=False)
1) beta = Vh.T*np.asmatrix(np.diag(1/s))*U.T*Y
2) beta = np.dot(Vh.T, np.dot(np.diag(1/s), np.dot(U.T, Y)))
1) is with X and Y starting out as matrices, 2) is with arrays.
Even diag results in an array that has to be matricized. Sigh.
--
View this message in context: http://www.nabble.com/matrix-default-to-column-vector--tp23652920p24023215.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.
More information about the NumPy-Discussion
mailing list