Python Griddata:ValueError:数据类型<;类型';numpy.int64'&燃气轮机;非不精确或值错误:形状不匹配

Python Griddata:ValueError:数据类型<;类型';numpy.int64'&燃气轮机;非不精确或值错误:形状不匹配,python,python-2.7,matplotlib,scipy,interpolation,Python,Python 2.7,Matplotlib,Scipy,Interpolation,我有一张1023835分的名单。每个点都是坐标x和y以及高度z的列表。 我有:max(x)=9940和max(y)=6445 我想用mlab或scipy.interpolate对后者进行插值 所以我尝试了不同的代码。它们及其各自的错误: import numpy as np import matplotlib.pyplot as plt import scipy.interpolate as si import matplotlib.mlab as ml # grid the data. x,

我有一张1023835分的名单。每个点都是坐标x和y以及高度z的列表。 我有:
max(x)=9940
max(y)=6445
我想用mlab或scipy.interpolate对后者进行插值

所以我尝试了不同的代码。它们及其各自的错误:

import numpy as np
import matplotlib.pyplot as plt
import scipy.interpolate as si
import matplotlib.mlab as ml

# grid the data.
x,y,z = zip(*bathy) 
xi = np.arange(0,max(x))
yi = np.arange(0,max(y))

zi = ml.griddata(x, y, z, xi, yi, interp='linear')  #griddata from mlab
#zi = si.griddata((x, y),z, (xi, yi), method='linear',fill_value=0) #griddata from scipy.intperlate
fig = plt.figure()

plt.scatter(y, x, color='g', marker='o', alpha=0.5)
plt.colorbar
plt.show()


ValueError回溯(最近一次调用)
在()
5.
Milab的6×Zi=ML.GrDATA(x,y,z,席,y,ipp=’线性’)GrIDATA数据
---->7 zi=si.griddata((x,y),z,(xi,yi),method='linear',fill_value=0)#来自scipy的griddata
8图=plt.图()
9#ax=图添加_子图(111,投影=3d)
/GRDATA中的/UR/Lyb/Python 2.7/Dist-Paygs/ScPy/ItPurATe/NDGRIDATATE.PYC(点、值、席、方法、FILIL值)
182 elif方法==‘线性’:
183 ip=LinearNDInterpolator(点、值、填充值=填充值)
-->184返回ip(xi)
185 elif方法=='cubic'和ndim==2:
186 ip=Cloughtocher2插值器(点、值、填充值=填充值)
/usr/lib/python2.7/dist-packages/scipy/interpolate/interpnd.so中的scipy.interpolatorbase.调用(scipy/interpolate/interpnd.c:1968)()
/usr/lib/python2.7/dist-packages/scipy/interpolate/interpnd.so中的scipy.interpolate.interpnd.\u ndim\u coords\u from_数组(scipy/interpolate/interpnd.c:2221)()
/广播数组中的usr/lib/pymodules/python2.7/numpy/lib/stride\u tricks.pyc(*args)
92#此轴必须至少有两个非1长度。
93 raise VALUETERROR(“形状不匹配:两个或多个数组已匹配”
--->94“轴%r.%(轴,)上的尺寸不兼容”
95 elif len(唯一)==2:
96#正好有一个非1长度。通常的形状是这样的
ValueError:形状不匹配:两个或多个阵列在轴0上的尺寸不兼容。

感谢
mlab.griddata
错误:您是否尝试将
xi
yi
的数据类型更改为浮点?例如,
xi=np.arange(0.0,max(x))
就可以了。我尝试了,我还更改了数据,因为它们太重了。为了测试我创建的其余代码:一个x列表,一个y列表和一个46个整数的z列表。但是我得到了一个带有
mlab.griddata
的空数字和
ValueError:si.griddata
的新数组的总大小必须保持不变。。。
ValueError                                Traceback (most recent call last)
<ipython-input-78-65f44ae4c4b5> in <module>()
      4 
      5 
----> 6 zi = ml.griddata(x, y, z, xi, yi, interp='linear')  #griddata from mlab
      7 #zi = si.griddata((x, y),z, (xi, yi), method='linear',fill_value=0)                     #griddata from scipy.intperlate
      8 fig = plt.figure()

/usr/lib/pymodules/python2.7/matplotlib/mlab.pyc in griddata(x, y, z, xi, yi, interp)
   2777             dx = xi[0,1:]-xi[0,0:-1]
   2778             dy = yi[1:,0]-yi[0:-1,0]
-> 2779             epsx = np.finfo(xi.dtype).resolution
   2780             epsy = np.finfo(yi.dtype).resolution
   2781             if dx.max()-dx.min() > epsx or dy.max()-dy.min() > epsy:

/usr/lib/pymodules/python2.7/numpy/core/getlimits.pyc in __new__(cls, dtype)
    105             dtype = newdtype
    106         if not issubclass(dtype, numeric.inexact):
--> 107             raise ValueError, "data type %r not inexact" % (dtype)
    108         obj = cls._finfo_cache.get(dtype,None)
    109         if obj is not None:

ValueError: data type <type 'numpy.int64'> not inexact
# grid the data.
x,y,z = zip(*bathy) 
xi = np.arange(0,max(x))
yi = np.arange(0,max(y))


#zi = ml.griddata(x, y, z, xi, yi, interp='linear') #griddata from mlab
zi = si.griddata((x, y),z, (xi, yi), method='linear',fill_value=0)          #griddata from scipy.intperlate

fig = plt.figure()
plt.scatter(y,x,color='g',marker='o', alpha=0.5)
plt.colorbar
plt.show()
ValueError                                Traceback (most recent call last)
<ipython-input-73-8936d8734f97> in <module>()
      5 
      6 #zi = ml.griddata(x, y, z, xi, yi, interp='linear')                                                                #griddata from mlab
----> 7 zi = si.griddata((x, y),z, (xi, yi), method='linear',fill_value=0)                      #griddata from scipy
      8 fig = plt.figure()
      9 #ax = fig.add_subplot(111, projection='3d')

/usr/lib/python2.7/dist-packages/scipy/interpolate/ndgriddata.pyc in griddata(points, values, xi, method, fill_value)
    182     elif method == 'linear':
    183         ip = LinearNDInterpolator(points, values, fill_value=fill_value)
--> 184         return ip(xi)
    185     elif method == 'cubic' and ndim == 2:
    186         ip = CloughTocher2DInterpolator(points, values, fill_value=fill_value)

/usr/lib/python2.7/dist-packages/scipy/interpolate/interpnd.so in scipy.interpolate.interpnd.NDInterpolatorBase.__call__ (scipy/interpolate/interpnd.c:1968)()

/usr/lib/python2.7/dist-packages/scipy/interpolate/interpnd.so in scipy.interpolate.interpnd._ndim_coords_from_arrays (scipy/interpolate/interpnd.c:2221)()

/usr/lib/pymodules/python2.7/numpy/lib/stride_tricks.pyc in broadcast_arrays(*args)
     92             # There must be at least two non-1 lengths for this axis.
     93             raise ValueError("shape mismatch: two or more arrays have "
---> 94                 "incompatible dimensions on axis %r." % (axis,))
     95         elif len(unique) == 2:
     96             # There is exactly one non-1 length. The common shape will take this

ValueError: shape mismatch: two or more arrays have incompatible dimensions on axis 0.