Griddata:ValueError:数据类型<type'numpy.int64'=“”>不精确或ValueError:形状不匹配

时间:2017-07-20 14:22:06

标签: python python-2.7 matplotlib scipy interpolation

我的列表bathy为1,023,835分。每个点是坐标x和y以及高度z的列表。 我有:max(x)= 9940max(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                                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

第二个几乎相同但是因为我使用了来自scipy的griddata,所以它可能很有用:

# 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.

由于

0 个答案:

没有答案