parameters: (*args, **kwargs)
docstring: n-dimensional gridding like Matlab's NDGRID
      
      The input *args are an arbitrary number of numerical sequences, 
      e.g. lists, arrays, or tuples.
      The i-th dimension of the i-th output argument 
      has copies of the i-th input argument.
      
      Optional keyword argument:
      same_dtype : If False (default), the result is an ndarray.
                   If True, the result is a lists of ndarrays, possibly with 
                   different dtype. This can save space if some *args 
                   have a smaller dtype than others.
  
      Typical usage:
      >>> x, y, z = [0, 1], [2, 3, 4], [5, 6, 7, 8]
      >>> X, Y, Z = ndgrid(x, y, z) # unpacking the returned ndarray into X, Y, Z
  
      Each of X, Y, Z has shape [len(v) for v in x, y, z].
      >>> X.shape == Y.shape == Z.shape == (2, 3, 4)
      True
      >>> X
      array([[[0, 0, 0, 0],
              [0, 0, 0, 0],
              [0, 0, 0, 0]],
             [[1, 1, 1, 1],
              [1, 1, 1, 1],
              [1, 1, 1, 1]]])
      >>> Y
      array([[[2, 2, 2, 2],
              [3, 3, 3, 3],
              [4, 4, 4, 4]],
             [[2, 2, 2, 2],
              [3, 3, 3, 3],
              [4, 4, 4, 4]]])
      >>> Z
      array([[[5, 6, 7, 8],
              [5, 6, 7, 8],
              [5, 6, 7, 8]],
             [[5, 6, 7, 8],
              [5, 6, 7, 8],
              [5, 6, 7, 8]]])
      
      With an unpacked argument list:
      >>> V = [[0, 1], [2, 3, 4]]
      >>> ndgrid(*V) # an array of two arrays with shape (2, 3)
      array([[[0, 0, 0],
              [1, 1, 1]],
             [[2, 3, 4],
              [2, 3, 4]]])
      
      For input vectors of different data types, same_dtype=False makes ndgrid()
      return a list of arrays with the respective dtype.
      >>> ndgrid([0, 1], [1.0, 1.1, 1.2], same_dtype=False)
      [array([[0, 0, 0], [1, 1, 1]]), 
       array([[ 1. ,  1.1,  1.2], [ 1. ,  1.1,  1.2]])]
      
      Default is to return a single array.
      >>> ndgrid([0, 1], [1.0, 1.1, 1.2])
      array([[[ 0. ,  0. ,  0. ], [ 1. ,  1. ,  1. ]],
             [[ 1. ,  1.1,  1.2], [ 1. ,  1.1,  1.2]]])
docstring_summary: n-dimensional gridding like Matlab's NDGRID
      
      The input *args are an arbitrary number of numerical sequences, 
      e.g. lists, arrays, or tuples.
      The i-th dimension of the i-th output argument 
      has copies of the i-th input argument.
      
      Optional keyword argument:
      same_dtype : If False (default), the result is an ndarray.
                   If True, the result is a lists of ndarrays, possibly with 
                   different dtype. This can save space if some *args 
                   have a smaller dtype than others.
docstring_tokens: n - dimensional gridding like Matlab s NDGRID The input * args are an arbitrary number of numerical sequences e . g . lists arrays or tuples . The i - th dimension of the i - th output argument has copies of the i - th input argument . Optional keyword argument : same_dtype : If False ( default ) the result is an ndarray . If True the result is a lists of ndarrays possibly with different dtype . This can save space if some * args have a smaller dtype than others .
function: def ndgrid(*args, **kwargs):
      """
      n-dimensional gridding like Matlab's NDGRID
      
      The input *args are an arbitrary number of numerical sequences, 
      e.g. lists, arrays, or tuples.
      The i-th dimension of the i-th output argument 
      has copies of the i-th input argument.
      
      Optional keyword argument:
      same_dtype : If False (default), the result is an ndarray.
                   If True, the result is a lists of ndarrays, possibly with 
                   different dtype. This can save space if some *args 
                   have a smaller dtype than others.
  
      Typical usage:
      >>> x, y, z = [0, 1], [2, 3, 4], [5, 6, 7, 8]
      >>> X, Y, Z = ndgrid(x, y, z) # unpacking the returned ndarray into X, Y, Z
  
      Each of X, Y, Z has shape [len(v) for v in x, y, z].
      >>> X.shape == Y.shape == Z.shape == (2, 3, 4)
      True
      >>> X
      array([[[0, 0, 0, 0],
              [0, 0, 0, 0],
              [0, 0, 0, 0]],
             [[1, 1, 1, 1],
              [1, 1, 1, 1],
              [1, 1, 1, 1]]])
      >>> Y
      array([[[2, 2, 2, 2],
              [3, 3, 3, 3],
              [4, 4, 4, 4]],
             [[2, 2, 2, 2],
              [3, 3, 3, 3],
              [4, 4, 4, 4]]])
      >>> Z
      array([[[5, 6, 7, 8],
              [5, 6, 7, 8],
              [5, 6, 7, 8]],
             [[5, 6, 7, 8],
              [5, 6, 7, 8],
              [5, 6, 7, 8]]])
      
      With an unpacked argument list:
      >>> V = [[0, 1], [2, 3, 4]]
      >>> ndgrid(*V) # an array of two arrays with shape (2, 3)
      array([[[0, 0, 0],
              [1, 1, 1]],
             [[2, 3, 4],
              [2, 3, 4]]])
      
      For input vectors of different data types, same_dtype=False makes ndgrid()
      return a list of arrays with the respective dtype.
      >>> ndgrid([0, 1], [1.0, 1.1, 1.2], same_dtype=False)
      [array([[0, 0, 0], [1, 1, 1]]), 
       array([[ 1. ,  1.1,  1.2], [ 1. ,  1.1,  1.2]])]
      
      Default is to return a single array.
      >>> ndgrid([0, 1], [1.0, 1.1, 1.2])
      array([[[ 0. ,  0. ,  0. ], [ 1. ,  1. ,  1. ]],
             [[ 1. ,  1.1,  1.2], [ 1. ,  1.1,  1.2]]])
      """
      same_dtype = kwargs.get("same_dtype", True)
      V = [array(v) for v in args] # ensure all input vectors are arrays
      shape = [len(v) for v in args] # common shape of the outputs
      result = []
      for i, v in enumerate(V):
          # reshape v so it can broadcast to the common shape
          # http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html
          zero = zeros(shape, dtype=v.dtype)
          thisshape = ones_like(shape)
          thisshape[i] = shape[i]
          result.append(zero + v.reshape(thisshape))
      if same_dtype:
          return array(result) # converts to a common dtype
      else:
          return result
function_tokens: def ndgrid ( * args , * * kwargs ) : same_dtype = kwargs . get ( "same_dtype" , True ) V = [ array ( v ) for v in args ] # ensure all input vectors are arrays shape = [ len ( v ) for v in args ] # common shape of the outputs result = [ ] for i , v in enumerate ( V ) : # reshape v so it can broadcast to the common shape # http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html zero = zeros ( shape , dtype = v . dtype ) thisshape = ones_like ( shape ) thisshape [ i ] = shape [ i ] result . append ( zero + v . reshape ( thisshape ) ) if same_dtype : return array ( result ) # converts to a common dtype else : return result