在numpy或scipy中左倒数? [英] Left inverse in numpy or scipy?

查看:90
本文介绍了在numpy或scipy中左倒数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用numpy或scipy获取python中非平方矩阵的左逆. 如何将以下Matlab代码转换为Python?

I am trying to obtain the left inverse of a non-square matrix in python using either numpy or scipy. How can I translate the following Matlab code to Python?

>> A = [0,1; 0,1; 1,0]

A =

     0     1
     0     1
     1     0

>> y = [2;2;1]

y =

     2
     2
     1

>> A\y

ans =

    1.0000
    2.0000

在Matlab中是否有与numpy或scipy等效的左逆\运算符?

Is there a numpy or scipy equivalent of the left inverse \ operator in Matlab?

推荐答案

使用linalg.lstsq(A,y),因为A不是正方形.有关详细信息,请参见此处.如果A是方形的,则可以使用linalg.solve(A,y),但不适用于您的情况.

Use linalg.lstsq(A,y) since A is not square. See here for details. You can use linalg.solve(A,y) if A is square, but not in your case.

这篇关于在numpy或scipy中左倒数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆