使用时零分区错误scipy.interpolate.gridd

2024-05-15 09:25:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我从以下代码中得到一个ZeroDivisionError

#stacking the array into a complex array allows np.unique to choose
#truely unique points.  We also keep a handle on the unique indices
#to allow us to index `self` in the same order.
unique_points,index = np.unique(xdata[mask]+1j*ydata[mask],
                         return_index=True)
#Now we break it into the data structure we need.
points = np.column_stack((unique_points.real,unique_points.imag))

xx1,xx2 = self.meta['rcm_xx1'],self.meta['rcm_xx2']
yy1 = self.meta['rcm_yy2']
gx = np.arange(xx1,xx2+dx,dx)
gy = np.arange(-yy1,yy1+dy,dy)
GX,GY = np.meshgrid(gx,gy)

xi = np.column_stack((GX.ravel(),GY.ravel()))
gdata = griddata(points,self[mask][index],xi,method='linear',
                           fill_value=np.nan)

这里,xdataydata和{}都是具有相同形状和dtype=np.float32的2D{}(或其子类)。mask是具有相同形状和dtype=bool的2dndarray。这里有一个链接给那些想阅读^{} documentation的人。在

最初,xdata和{}是从一个具有4点模板的非均匀柱面网格派生的——我认为错误可能来自于同一点被多次定义的事实,因此我按照建议使输入点集是唯一的in this question。不幸的是,这似乎没有帮助。完整的回溯是:

^{pr2}$

不管怎样,如果我使用“nearest”方法,代码“有效”(没有例外)。在


Tags: theto代码selfindexnpmaskmeta