docs: def cartesian(shape):
      r"""Cartesian indexing.
  
      Returns a sequence of n-tuples indexing each element of a hypothetical
      matrix of the given shape.
  
      Args:
          shape (tuple): tuple of dimensions.
  
      Returns:
          array_like: indices.
  
      Example
      -------
  
      .. doctest::
  
          >>> from numpy_sugar import cartesian
          >>> print(cartesian((2, 3)))
          [[0 0]
           [0 1]
           [0 2]
           [1 0]
           [1 1]
           [1 2]]
  
      Reference:
  
      [1] http://stackoverflow.com/a/27286794
      """
      n = len(shape)
      idx = [slice(0, s) for s in shape]
      g = rollaxis(mgrid[idx], 0, n + 1)
      return g.reshape((prod(shape), n))