code: def expanded_indexer(key, ndim):
      
      if not isinstance(key, tuple):
          # numpy treats non-tuple keys equivalent to tuples of length 1
          key = (key,)
      new_key = []
      # handling Ellipsis right is a little tricky, see:
      # http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#advanced-indexing
      found_ellipsis = False
      for k in key:
          if k is Ellipsis:
              if not found_ellipsis:
                  new_key.extend((ndim + 1 - len(key)) * [slice(None)])
                  found_ellipsis = True
              else:
                  new_key.append(slice(None))
          else:
              new_key.append(k)
      if len(new_key) > ndim:
          raise IndexError('too many indices')
      new_key.extend((ndim - len(new_key)) * [slice(None)])
      return tuple(new_key)
docs: Given a key for indexing an ndarray, return an equivalent key which is a
      tuple with length equal to the number of dimensions.
  
      The expansion is done by replacing all `Ellipsis` items with the right
      number of full slices and then padding the key with full slices so that it
      reaches the appropriate dimensionality.