将线性表面与numpy最小二乘拟合 [英] fitting a linear surface with numpy least squares

查看:161
本文介绍了将线性表面与numpy最小二乘拟合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想求解方程式z= a + b*y +c*x.获取a,b,c. 即:使(平面)表面适合3D空间中的分散点负载.

So I want to solve the equation z= a + b*y +c*x,. getting a,b,c. ie: making a (plane) surface fit to a load of scatter points in 3D space.

但是我似乎什么也找不到!我以为会有这样一个简单的问题的简单模块.

But I can't seem to find anything! I thought there would be a simple module for such a simple problem.

我已经尝试过,其中x,y,z是数组;

I have tried, where x,y,z are arrays;

ys=zip(x,y)
(coeffs, residuals, rank, sing_vals) = np.linalg.lstsq(ys,z)

我认为coeffs = b,c是正确的吗? 还是我完全朝错误的方向前进.我似乎找不到其他可以在3d模式下工作的东西...

am I right in thinking coeffs = b,c? Or am I going completely in the wrong direction. I just can't seem to find anything else that will work in 3d...

推荐答案

我认为您的做法正确.您仍然可以尝试按照 scipy.linalg文档的示例进行操作. ,特别是求解最小二乘..."部分

I think you're on the right track. You could still try following the example of the scipy.linalg documentation, in particular the Solving least-squares...` section

A = np.column_stack((np.ones(x.size), x, y))
c, resid,rank,sigma = np.linalg.lstsq(A,zi)

(我们为常数添加了1列).

(we added a column of 1 for the constant).

这篇关于将线性表面与numpy最小二乘拟合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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