Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Numpy 等间距数据的N-D插值_Numpy_Scipy - Fatal编程技术网

Numpy 等间距数据的N-D插值

Numpy 等间距数据的N-D插值,numpy,scipy,Numpy,Scipy,我正在尝试复制Scipy Cookbook函数: from scipy import ogrid, sin, mgrid, ndimage, array x,y = ogrid[-1:1:5j,-1:1:5j] fvals = sin(x)*sin(y) newx,newy = mgrid[-1:1:100j,-1:1:100j] x0 = x[0,0] y0 = y[0,0] dx = x[1,0] - x0 dy = y[0,1] - y0 ivals = (newx - x0)/dx jv

我正在尝试复制Scipy Cookbook函数:

from scipy import ogrid, sin, mgrid, ndimage, array
x,y = ogrid[-1:1:5j,-1:1:5j]
fvals = sin(x)*sin(y)
newx,newy = mgrid[-1:1:100j,-1:1:100j]
x0 = x[0,0]
y0 = y[0,0]
dx = x[1,0] - x0
dy = y[0,1] - y0
ivals = (newx - x0)/dx
jvals = (newy - y0)/dy
coords = array([ivals, jvals])
newf = ndimage.map_coordinates(fvals, coords)
通过使用我自己的函数,该函数必须适用于许多场景

import scipy
import numpy as np
"""N-D interpolation for equally-spaced data"""                                         
x = np.c_[plist['modx']]                                                                
y = np.transpose(np.c_[plist['mody']])                                                  
pdb.set_trace()                                                                         
#newx,newy = np.meshgrid(plist['newx'],plist['newy'])                                   
newx,newy = scipy.mgrid[plist['modx'][0]:plist['modx'][-1]:-plist['remapto'],               
                     plist['mody'][0]:plist['mody'][-1]:-plist['remapto']]                                                                                        
x0 = x[0,0]                                                                             
y0 = y[0,0]                                                                             
dx = x[1,0] - x0                                                                        
dy = y[0,1] - y0                                                                        
ivals = (newx - x0)/dx                                                                  
jvals = (newy - y0)/dy                                                                  
coords = scipy.array([ivals, jvals])                                                    
for i in np.arange(ivals.shape[0]):                                                     
    nvals[i] = scipy.ndimage.map_coordinates(ivals[i], coords)                                                                                                                              
我很难让这个代码正常工作。问题在于: 1.)重新创建此行:newx,newy=mgrid[-1:1:100j,-1:1:100j]。在我的例子中,我有一个向量形式的网格字典。我试图使用np.meshgrid重新创建这一行,但在coords=scipy.array([ivals,jvals])行上出现了一个错误。我正在寻找一些帮助来重新创建这个食谱功能,使它更具活力 非常感谢您的帮助


/M

您应该查看有关的文档。我看不出您试图插入的实际数据在代码中的位置。我的意思是,假设你有一些数据
输入
,它是
x
y
的函数;i、 e.
input=f(x,y)
要插值的。在您显示的第一个示例中,这是数组
fvals
。这应该是
映射坐标的第一个参数

例如,如果您尝试输入的数据是
input
,它应该是形状
(len(x),len(y))
的二维数组,则插入的数据将是:

interpolated_data = map_coordinates(input, coords)

你说网格是“向量”形式是什么意思?你能发布一个数组的样本吗?很抱歉。我所说的向量是一维数组。例如,plist['modx']例如,plist['modx''modx']阵列([10.125,9.875,7.875,5.625,5.625,4.5,3.5,3.5,5.5,5.5 5 5,7.75,5.5 5,7.75,5.5 5,5.5,5.5,5,3.5,3.375,3.5,3.375,3.5,3.5,3.375,3.5,3.5,1.25,1.25,1.125,1.125,1.125,1.125,-1.125,-1.125、1.125,-1.125,-1.125,--1.125,--1.125,-0、-0,--0、-0、-1.125,--1.125,--2.25,--2.25,--2.25,--2.25,--2.25,--PTO']0.703125输入IVAS具有尺寸(19,19)。假设该函数将分辨率从1.125提高到0.703125。您从当前代码中得到了什么错误?此外,您当前的代码示例不是有效的python。有一个
return
语句不在函数内部。当前窗体的“坐标数组的形状无效”。我必须重新排列它以获得np.meshgrid的错误。ivals是一个2D数组(19,19),coords有了新的形状,但它是3D的:(2,31,31)。cookbook的例子是有效的,但我一直从coords那里得到一个错误。我仍然无法让这个插值工作。在阅读了关于map_坐标和重写函数之后,我得到了错误的结果。数据被篡改和替换。这种2D双线性插值在scipy中是否可行?请编辑您的问题并发布更新的代码,最好是使用小示例数组,然后发布您期望的内容和得到的内容。Map_坐标导致的结果不正确且有些混乱。有效的解决方案使用griddata。这里是它的要点:lats=plist['xlats'];lons=plist['xlons'];lat_old,lon_old=np.meshgrid(lats,lons)lon_new=plist['newx']+lon;lat_new=plist['newy']+lat_new=lat_new[:-1]nvals[i]=matplotlib.mlab.griddata(lat_old.flatte(),lon_old.flatte(),ivals[i].flatte(),lat_new,lon_new)