简体   繁体   English

反转numpy.dot

[英]Inverse of numpy.dot

I can easily calculate something like: 我可以轻松计算出类似的东西:

R = numpy.column_stack([A,np.ones(len(A))]) 
M = numpy.dot(R,[k,m0])

where A is a simple array and k,m0 are known values. 其中A是一个简单的数组,k,m0是已知值。

I want something different. 我想要不同的东西。 Having fixed R, M and k, I need to obtain m0. 固定了R,M和k后,我需要获得m0。 Is there a way to calculate this by an inverse of the function numpy.dot()? 有没有办法通过函数numpy.dot()的反函数来计算它? Or it is only possible by rearranging the matrices? 或者只能通过重新排列矩阵来实现?

M = numpy.dot(R,[k,m0])

is performing matrix multiplication. 正在执行矩阵乘法。 M = R * x . M = R * x

So to compute the inverse, you could use np.linalg.lstsq(R, M) : 所以要计算逆,你可以使用np.linalg.lstsq(R, M)

import numpy as np
A = np.random.random(5)
R = np.column_stack([A,np.ones(len(A))]) 
k = np.random.random()
m0 = np.random.random()
M = R.dot([k,m0])

(k_inferred, m0_inferred), residuals, rank, s = np.linalg.lstsq(R, M)

assert np.allclose(m0, m0_inferred)
assert np.allclose(k, k_inferred)

Note that both k and m0 are determined, given M and R (assuming len(M) >= 2 ). 注意,这两个 km0被确定,给定的MR假定len(M) >= 2 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM