4

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都是self具有numpy.ndarray相同形状的 2D (或其子类) 和dtype=np.float32mask是具有相同形状的 2dndarraydtype=bool。这里有一个链接供那些想要阅读scipy.interpolate.griddata文档的人使用。

最初,xdata并且ydata是从具有 4 点模板的非均匀圆柱形网格派生的——我认为错误可能来自同一点被多次定义的事实,所以我将输入点集设置为唯一在这个问题中建议。不幸的是,这似乎没有帮助。完整的追溯是:

Traceback (most recent call last):
  File "/xxxxxxx/rcm.py", line 428, in <module>
    x[...,1].to_pz0()
  File "/xxxxxxx/rcm.py", line 285, in to_pz0
    fill_value=fill_value)
  File "/usr/local/lib/python2.7/site-packages/scipy/interpolate/ndgriddata.py", line 183, in griddata
    ip = LinearNDInterpolator(points, values, fill_value=fill_value)
  File "interpnd.pyx", line 192, in scipy.interpolate.interpnd.LinearNDInterpolator.__init__ (scipy/interpolate/interpnd.c:2935)
  File "qhull.pyx", line 996, in scipy.spatial.qhull.Delaunay.__init__ (scipy/spatial/qhull.c:6607)
  File "qhull.pyx", line 183, in scipy.spatial.qhull._construct_delaunay (scipy/spatial/qhull.c:1919)
ZeroDivisionError: float division

对于它的价值,如果我使用“最近”方法,代码“有效”(没有例外)。

4

0 回答 0