docs: def valid_index(index, shape) -> tuple:
      """Get a valid index for a broadcastable shape.
  
      Parameters
      ----------
      index : tuple
          Given index.
      shape : tuple of int
          Shape.
  
      Returns
      -------
      tuple
          Valid index.
      """
      # append slices to index
      index = list(index)
      while len(index) < len(shape):
          index.append(slice(None))
      # fill out, in reverse
      out = []
      for i, s in zip(index[::-1], shape[::-1]):
          if s == 1:
              if isinstance(i, slice):
                  out.append(slice(None))
              else:
                  out.append(0)
          else:
              out.append(i)
      return tuple(out[::-1])