![](/img/trans.png)
[英]3D volume acrobatics in python.. selecting x/y/z rows/columns in 3D numpy arrays
[英]Python: How can I apply the polyfit feature in 3D with 3 arrays x[], y[], z[]
我有这 3 个 arrays 和我的数据:
X=np.array(x)
Y=np.array(y)
Z=np.array(z)
我知道如何 plot 我的观点,以及如何在 2D 中应用 polyfit。 如何从 3D 中的数据中获取 polyfit 系数? 我可以 plot 我的 3D 拟合曲线吗?
我不确定是否可以使用np.polyfit()
,但我在这里找到了可以帮助的参考。 它实现如下查找系数:
import numpy as np
# note I have changed the capital to lowercase since the rest of the code is that way
x=np.array(x)
y=np.array(y)
z=np.array(z)
degree = 3
# Set up the canonical least squares form
Ax = np.vander(x, degree)
Ay = np.vander(y, degree)
A = np.hstack((Ax, Ay))
# Solve for a least squares estimate
(coeffs, residuals, rank, sing_vals) = np.linalg.lstsq(A, z)
# Extract coefficients and create polynomials in x and y
xcoeffs = coeffs[0:degree]
ycoeffs = coeffs[degree:2 * degree]
fx = np.poly1d(xcoeffs)
fy = np.poly1d(ycoeffs)
我希望您正在寻找的,关于计算的进一步扩展在上面的链接中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.