numpy.meshgrid explanation
<p>Could someone care to explin the <code>meshgrid</code> method ? I cannot wrap my mind around it. The example is from the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html#numpy.meshgrid" rel="nofollow">SciPy</a> site:</p>

<pre><code>import numpy as np

nx, ny = (3, 2)
x = np.linspace(0, 1, nx)
print ("x =", x)

y = np.linspace(0, 1, ny)
print ("y =", y)

xv, yv = np.meshgrid(x, y)
print ("xv_1 =", xv)
print ("yv_1 =",yv)


xv, yv = np.meshgrid(x, y, sparse=True)  # make sparse output arrays
print ("xv_2 =", xv)

print ("yv_2 =", yv)
</code></pre>

<p>Printout is :</p>

<pre><code>x = [ 0.   0.5  1. ]
y = [ 0.  1.]
xv_1 = [[ 0.   0.5  1. ]
 [ 0.   0.5  1. ]]
yv_1 = [[ 0.  0.  0.]
 [ 1.  1.  1.]]
xv_2 = [[ 0.   0.5  1. ]]
yv_2 = [[ 0.]
 [ 1.]]
</code></pre>

<p>Why are arrays xv_1 and yv_1 formed like this ? Ty :)</p>

<p>Your linear spaced vectors <code>x</code> and <code>y</code> defined by <code>linspace</code> use 3 and 2 points respectively. </p>

<p>These linear spaced vectors are then used by the meshgrid function to create a 2D linear spaced point cloud. This will be a grid of points for each of the <code>x</code> and <code>y</code> coordinates. The size of this point cloud will be 3 x 2.</p>

<p>The output of the function <code>meshgrid</code> creates an indexing matrix that holds in each cell the <code>x</code> and <code>y</code> coordinates for each point of your space.</p>

<p>This is created as follows:</p>

<pre><code># dummy
def meshgrid_custom(x,y):
xv = np.zeros((len(x),len(y)))
yv = np.zeros((len(x),len(y)))

for i,ix in zip(range(len(x)),x):
    for j,jy in zip(range(len(y)),y):
        xv[i,j] = ix
        yv[i,j] = jy

return xv.T, yv.T
</code></pre>

<p>So, for example the point at the location (1,1) has the coordinates:</p>

<p><code>x = xv_1[1,1] = 0.5</code><br>
<code>y = yv_1[1,1] = 1.0</code></p>

python numpy