def __getitem__(self, indices):
        """Return ``self[indices]``."""
        if isinstance(indices, Integral):
            return self.parts[indices]
        elif isinstance(indices, slice):
            return self.space[indices].element(self.parts[indices])
        elif isinstance(indices, list):
            out_parts = [self.parts[i] for i in indices]
            return self.space[indices].element(out_parts)
        elif isinstance(indices, tuple):
            if len(indices) == 0:
                return ProductSpace().element()
            elif len(indices) == 1:
                # Tuple with a single entry - we just unpack and delegate
                return self[indices[0]]
            else:
                # Tuple with multiple entries
                if isinstance(indices[0], Integral):
                    # In case the first entry is an integer, we drop the
                    # axis and return directly from `parts`
                    return self.parts[indices[0]][indices[1:]]
                else:
                    # indices[0] is a slice or list. We first retrieve the
                    # parts indexed in this axis.
                    # In any case we know that we want to keep this axis.
                    if isinstance(indices[0], list):
                        part = [self.parts[i] for i in indices[0]]
                    else:
                        part = self.parts[indices[0]]

                    if (len(indices[1:]) == 1 and
                            not all(isinstance(p, ProductSpaceElement)
                                    for p in part)):
                        # This case means we have "hit the bottom", i.e.,
                        # there are non-ProductSpaces involved. In order
                        # not to retrieve scalar values from these
                        # elements, we use a slice of size 1.
                        idx = indices[1]
                        indexed = [p[idx:idx + 1] for p in part]
                    else:
                        # Here we're still in the "product space chain",
                        # so we can use recursion to go on.
                        indexed = [p[indices[1:]] for p in part]

                    # Finally make a wrapping space for the indexed elements
                    new_space = ProductSpace(*(p.space for p in indexed))
                    return new_space.element(indexed)
        else:
            raise TypeError('bad index type {}'.format(type(indices)))
def __getitem__ ( self , indices ) : if isinstance ( indices , Integral ) : return self . parts [ indices ] elif isinstance ( indices , slice ) : return self . space [ indices ] . element ( self . parts [ indices ] ) elif isinstance ( indices , list ) : out_parts = [ self . parts [ i ] for i in indices ] return self . space [ indices ] . element ( out_parts ) elif isinstance ( indices , tuple ) : if len ( indices ) == 0 : return ProductSpace ( ) . element ( ) elif len ( indices ) == 1 : return self [ indices [ 0 ] ] else : if isinstance ( indices [ 0 ] , Integral ) : return self . parts [ indices [ 0 ] ] [ indices [ 1 : ] ] else : if isinstance ( indices [ 0 ] , list ) : part = [ self . parts [ i ] for i in indices [ 0 ] ] else : part = self . parts [ indices [ 0 ] ] if ( len ( indices [ 1 : ] ) == 1 and not all ( isinstance ( p , ProductSpaceElement ) for p in part ) ) : idx = indices [ 1 ] indexed = [ p [ idx : idx + 1 ] for p in part ] else : indexed = [ p [ indices [ 1 : ] ] for p in part ] new_space = ProductSpace ( * ( p . space for p in indexed ) ) return new_space . element ( indexed ) else : raise TypeError ( 'bad index type {}' . format ( type ( indices ) ) )
Return ``self[indices]``.