numpy 线性代数基本帮助

发布于 2024-07-19 19:54:26 字数 704 浏览 3 评论 0原文

这就是我需要做的 -

我有这个方程 -

Ax = y

其中 A 是有理 m*n 矩阵 (m<=n),x 和 y 是向量 合适的大小。 我知道A和y,我不知道x等于什么。 我 还知道不存在 Ax 恰好等于 y 的 x。 我想找到向量 x' 使得 Ax' 尽可能接近 y。 这意味着 (Ax' - y) 尽可能接近 (0,0,0,...0)。

我知道我需要使用 lstsq 函数: http://www.scipy.org/doc/numpy_api_docs/ numpy.linalg.linalg.html#lstsq

或 svd 函数: http://www.scipy.org/doc/numpy_api_docs/ numpy.linalg.linalg.html#svd

我根本不理解文档。 有人可以展示一下吗 我如何使用这些功能来解决我的问题。

多谢!!!

This is what I need to do-

I have this equation-

Ax = y

Where A is a rational m*n matrix (m<=n), and x and y are vectors of
the right size. I know A and y, I don't know what x is equal to. I
also know that there is no x where Ax equals exactly y.
I want to find the vector x' such that Ax' is as close as possible to
y. Meaning that (Ax' - y) is as close as possible to (0,0,0,...0).

I know that I need to use either the lstsq function:
http://www.scipy.org/doc/numpy_api_docs/numpy.linalg.linalg.html#lstsq

or the svd function:
http://www.scipy.org/doc/numpy_api_docs/numpy.linalg.linalg.html#svd

I don't understand the documentation at all. Can someone please show
me how to use these functions to solve my problem.

Thanks a lot!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海之角 2024-07-26 19:54:26

更新的文档 可能更有帮助...看起来像你想要的

numpy.linalg.lstsq(A, y)

The updated documentation may be a bit more helpful... looks like you want

numpy.linalg.lstsq(A, y)
夢归不見 2024-07-26 19:54:26

SVD适用于m<1的情况。 n,因为你确实没有足够的自由度。

lstsq 的文档看起来不太有帮助。 我相信这是最小二乘拟合,对于 m > 的情况。 名词

如果m< n,您需要 SVD

SVD is for the case of m < n, because you don't really have enough degrees of freedom.

The docs for lstsq don't look very helpful. I believe that's least square fitting, for the case where m > n.

If m < n, you'll want SVD.

够钟 2024-07-26 19:54:26

矩阵 A 的 SVD 给出正交矩阵 U 和 V 以及对角矩阵 Σ,使得

A = U Σ V T

哪里
U UT = I ;
V VT = I

因此,如果

x A=<强>y

然后

<强>x<强>U<强>Σ<强>VT = y

x U Σ V T V = y V

x U Σ = y V

U T x Σ = y V

x Σ = U y <强>V

x = Σ -1 U T <强>y V

x = V T Σ -1 U T y

所以给定 A 的 SVD,你可以得到 x


虽然对于一般矩阵 A B != B A,但对于向量 x 来说,x U == 是正确的>U T x

例如,考虑 x = ( x, y ), U = ( a, b ; c, d ):

x U = ( x, y ) ( a, b ; c, d )

= ( xa+yc, xb+yd )

= ( ax+cy, bx+dy )

= ( a, c; b, d ) ( x; y )

= U T x

当你查看 x 中的值时,这是相当明显的 UxU 的列的点积,以及 UTxxUT的行的点积,以及行和的关系转置列

The SVD of matrix A gives you orthogonal matrices U and V and diagonal matrix Σ such that

A = U Σ V T

where
U UT = I ;
V VT = I

Hence, if

x A = y

then

x U Σ V T = y

x U Σ V T V = y V

x U Σ = y V

U T x Σ = y V

x Σ = U y V

x = Σ -1 U T y V

x = V T Σ -1 U T y

So given SVD of A you can get x.


Although for general matrices A B != B A, it is true for vector x that x U == U T x.

For example, consider x = ( x, y ), U = ( a, b ; c, d ):

x U = ( x, y ) ( a, b ; c, d )

= ( xa+yc, xb+yd )

= ( ax+cy, bx+dy )

= ( a, c; b, d ) ( x; y )

= U T x

It's fairly obvious when you look at the values in x U being the dot products of x and the columns of U, and the values in UTx being the dot products of the x and the rows of UT, and the relation of rows and columns in transposition

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文