Error in python griddata: "builtins.IndexError: index 0 is out of bounds for axis 0 with size 0"
Question: ## Griddata error

(adapted from: [Matplotlib contour from xyz data: griddata invalid
index](http://stackoverflow.com/questions/13781025/matplotlib-contour-from-
xyz-data-griddata-invalid-index))

I have a matrix of some values corresponding to a set of coordinates. I want
to load the data from an external file and use a griddata object to
interpolate between the points. However when running the code i get the error:

"builtins.IndexError: index 0 is out of bounds for axis 0 with size 0" from
griddata. I have no idea what this means?

A piece of sample code:

    
    
    def main():
    #http://stackoverflow.com/questions/13781025/matplotlib-contour-from-xyz-data-griddata-invalid-index
    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.mlab as ml
    
    ndata = 121
    ny, nx = 100, 200
    xmin, xmax = 0, 10
    ymin, ymax = 0, 10
    
    Data = np.loadtxt('Data.dat')
    Data = Data.flatten(1)
    
    x = np.array([j for i in np.arange(0,11,1) for j in np.arange(0,11,1)])
    y = np.array([j for i in np.arange(0,11,1) for j in np.arange(0,11,1)])
    #x = np.random.randint(xmin, xmax, ndata)
    #y = np.random.randint(ymin, ymax, ndata)
    
    xi = np.linspace(xmin, xmax, nx)
    yi = np.linspace(ymin, ymax, ny)
    zi = ml.griddata(x, y, Data, xi, yi)
    
    plt.contour(xi, yi, zi, 15, linewidths = 0.5, colors = 'k')
    plt.pcolormesh(xi, yi, zi, cmap = plt.get_cmap('rainbow'))
    
    plt.scatter(x, y, marker = 'o', c = 'b', s = 5, zorder = 10)
    plt.xlim(xmin, xmax)
    plt.ylim(ymin, ymax)
    plt.show()
    

Data.dat may be obtained from: <http://pastebin.com/Uk8SHA1F>

Notice how it works with the comprehensions supplying either x or y in
combination with the other coordinate being the random coordinate (commented),
but not when using comprehensions for both x and y?


Answer: "builtins.IndexError: index 0 is out of bounds for axis 0 with size 0" from
griddata. I have no idea what this means?

`index 0 is out of bounds for axis 0 with size 0`

You would get this error, when 1-D array is supplied when 2-D is expected, and
the first index is out of bounds. For example:

    
    
    >>> np.array([])[0,:]
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    IndexError: index 0 is out of bounds for axis 0 with size 0
    
    >>> np.array([2,4])[3,:]
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    IndexError: index 3 is out of bounds for axis 0 with size 2
    

Note that if you didn't specify any value for 2nd axis, you would get a
different error:

    
    
    >>> np.array([])[0]
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    IndexError: index out of bounds
    

