I amtrying to translate an IDL program to Python. I have to solve the outcome from SVD which I achieve in the following way
from scipy.linalg import svd
A = [[1,2,3],[4,5,6]]
b = [4,4,5]
u,w,v = svd(A)
And this works fine and is translated nicely from IDL. The next step is IN IDL(!)
x = svsol(u,w,v,b)
The u in python and IDL are almost the same (and for the other matrix’s as well). The only difference is the dimensions, where IDL’s matrix’s is larger, but has a lot of zeros. It looks like Python’s matrix’s are more compressed in that sence.
Does anyone know something similarly for Python.
If anyone needs it, here is the manual for svsol.
With
SVDCandSVSOLin IDL you solve a linear least squares problem by SVD decomposition. This is done innumpyby thenumpy.linalg.lstsqfunction. (No need to compute first the SVD decomposition and then back solve.)Please note that the length of
bhas to be the same as the number of rows ofA, so your example is wrong. Just to make shure that I’m correctly interpreting the IDL semantics, here is the example in thesvsolreference manual: