数组分割-从MATLAB转换为Python [英] Array division- translating from MATLAB to Python

查看:95
本文介绍了数组分割-从MATLAB转换为Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MATLAB中有这行代码,是由其他人编写的:

I have this line of code in MATLAB, written by someone else:

c=a.'/b

我需要将其翻译成Python. a,b和c都是数组.我当前用于测试代码的尺寸为:

I need to translate it into Python. a, b, and c are all arrays. The dimensions that I am currently using to test the code are:

a:18x1,
b:25x18,

a: 18x1,
b: 25x18,

这使我的c的尺寸为1x25.

which gives me c with dimensions 1x25.

数组不是方形的,但是我不想让代码失败.有人可以确切地(数学上)解释这一行在做什么,以及如何在Python中做到吗? (即,如果存在于Python中,则等同于MATLAB中的内置mrdivide函数吗?)

The arrays are not square, but I would not want the code to fail if they were. Can someone explain exactly what this line is doing (mathematically), and how to do it in Python? (i.e., the equivalent for the built-in mrdivide function in MATLAB if it exists in Python?)

推荐答案

c = a.' / b

计算 c 的方程式 c b = a T 的解. Numpy没有直接执行此操作的运算符.相反,您应该为 c T 解决 b T c T = a 并转置结果:

computes the solution of the equation c b = aT for c. Numpy does not have an operator that does this directly. Instead you should solve bT cT = a for cT and transpose the result:

c = numpy.linalg.lstsq(b.T, a.T)[0].T

这篇关于数组分割-从MATLAB转换为Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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