mak*_*ghi 6 python interpolation scipy
我有三列非结构化数据,并希望对它们进行双变量样条拟合.我对Python中的类不太好,所以我不明白如何做到这一点.为了表明我的问题,我做了一个简单的代码:
#! /usr/bin/env python3
import numpy as np
from scipy import interpolate
#an array of 3 columns:
a=np.zeros((200, 3))
a[:,0]=np.random.uniform(0,1,200)
a[:,1]=np.random.uniform(3,5,200)
a[:,2]=np.random.uniform(10,12,200)
#find the boundries
min_x, max_x = np.amin(a[:,0]), np.amax(a[:,0])
min_y, max_y = np.amin(a[:,1]), np.amax(a[:,1])
#Set the resolution:
x_res=1000
y_res=int( ( (max_y-min_y) / (max_x-min_x) )*x_res )
#Make a grid
grid_x, grid_y = np.mgrid[min_x:max_x:x_res*1j, min_y:max_y:y_res*1j]
sbsp=interpolate.SmoothBivariateSpline(a[:,0], a[:,1], a[:,2])
b=sbsp.ev(4,5)
#c=sbsp.ev(grid_x, grid_y)
print(b)
Run Code Online (Sandbox Code Playgroud)
这给出了一个点的插值,但如果你注释掉第二个最后一行,它就不起作用.如果有人能指导我如何在网格上进行样条插值,我将非常感激.提前致谢.
该方法ev(x,y)
要求x
和y
是一维数组。在您的代码中,grid_x
和grid_y
是二维的。
您可以尝试以下操作:
c=sbsp.ev(grid_x[0,0], grid_y[0,0])
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3559 次 |
最近记录: |