def ndmeshgrid(*arrs):
<EOL>arrs = tuple(arrs)<EOL>lens = list(map(len, arrs))<EOL>dim = len(arrs)<EOL>sz = <NUM_LIT:1><EOL>for s in lens:<EOL><INDENT>sz *= s<EOL><DEDENT>ans = []<EOL>for i, arr in enumerate(arrs):<EOL><INDENT>slc = [<NUM_LIT:1>] * dim<EOL>slc[i] = lens[i]<EOL>arr2 = numpy.asanyarray(arr).reshape(slc)<EOL>for j, sz in enumerate(lens):<EOL><INDENT>if j != i:<EOL><INDENT>arr2 = arr2.repeat(sz, axis=j)<EOL><DEDENT><DEDENT>ans.append(arr2)<EOL><DEDENT>return tuple(ans)<EOL>
Return a mesh grid for N dimensions.

    The input are N arrays, each of which contains the values along one axis of
    the coordinate system. The arrays do not have to have the same number of
    entries. The function returns arrays that can be fed into numpy functions
    so that they produce values for *all* points spanned by the axes *arrs*.

    Original from
    http://stackoverflow.com/questions/1827489/numpy-meshgrid-in-3d and fixed.

    .. SeeAlso: :func:`numpy.meshgrid` for the 2D case.