[英]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.