[Numpy-discussion] SVD problem - matrices are not aligned
Daniel Wagner
daniel.wagner.ml at googlemail.com
Sat Oct 23 23:47:34 EDT 2010
On Oct 23, 2010, at 11:25 PM, Charles R Harris wrote:
>
>
> On Sat, Oct 23, 2010 at 9:21 PM, Daniel Wagner <daniel.wagner.ml at googlemail.com> wrote:
>
> On Oct 23, 2010, at 10:48 PM, Charles R Harris wrote:
>
>>
>>
>> On Sat, Oct 23, 2010 at 8:33 PM, Daniel Wagner <daniel.wagner.ml at googlemail.com> wrote:
>>> On Sat, Oct 23, 2010 at 7:00 PM, Daniel Wagner <daniel.wagner.ml at googlemail.com> wrote:
>>> Hi,
>>>
>>> I'm a new subscriber of this list. I hope to directly start with a question is ok...
>>>
>>> My question or problem:
>>> I've a matrix A which is calculated from the data b. The shapes of these matrices are:
>>> >>>A.shape
>>> (954, 9)
>>> >>>b.shape
>>> (954,)
>>>
>>> I calculate the SVD of A:
>>> >>> U, w, V = numpy.linalg.svd(A, full_matrices="True")
>>> >>>U.shape
>>> (954, 954)
>>>
>>> You want full_matrices set false so that U has shape (954, 9).
>>>
>> thanks! I tried it before with "False" as a string but of course this couldn't work. omgh. (no error message?)
>> Now I'm using:
>> >>>U, w, V = numpy.linalg.svd(yz_matrix_by, full_matrices=False)
>>
>>> >>>W.diag(w)
>>> >>>W.shape
>>> (9,9)
>>> >>>V.shape
>>> (9,9)
>>>
>>> If I'm doing the check of the SVD results using:
>>> >>>numpy.allclose(A, numpy.dot(U, numpy.dot(W, V)))
>>> I get this error:
>>>
>>> easier, allclose(A, dot(U*w, V) )
>>>
>> That's right!
>>
>>>
>>> "ValueError: matrices are not aligned"
>>>
>>>
>>> Mismatched dimensions.
>>>
>>
>> Yeah, this error is away. Now I get:
>> >>>print(numpy.allclose(U_by*w_by, V_by))
>> False
>>
>>
>> Seems to be a missing "dot" in there.
>>
>
> The following works:
> >>>numpy.allclose(A, numpy.dot(U, numpy.dot(W, V)))
> True
>
> But now I've a new problem problem:
>
> When I'm using:
>
> >>> A.shape
> (954, 9)
> >>> b.shape
> (954, )
> >>> temp = numpy.linalg.pinv(A, rcond=1.0000000000000001e-15)
> >>> temp.shape
> (9, 954)
>
> to multiply this with my data b
> >>>x = numpy.dot(temp, b)
> ValueError: matrices are not aligned
>
> I've missmatched dimensions again....
>
>
> Looks like you might want to look at lstsq.
>
It works like a charm! The next time I really should use the already implemented functions and if I'm unsure how they work I still can take a look into their source code...
Thank you for the hint!
Greetings,
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20101023/69c574aa/attachment.html>
More information about the NumPy-Discussion
mailing list