code: def byaxis(self):
          
          space = self
  
          class NpyTensorSpacebyaxis(object):
  
              """Helper class for indexing by axis."""
  
              def __getitem__(self, indices):
                  """Return ``self[indices]``."""
                  try:
                      iter(indices)
                  except TypeError:
                      newshape = space.shape[indices]
                  else:
                      newshape = tuple(space.shape[i] for i in indices)
  
                  if isinstance(space.weighting, ArrayWeighting):
                      new_array = np.asarray(space.weighting.array[indices])
                      weighting = NumpyTensorSpaceArrayWeighting(
                          new_array, space.weighting.exponent)
                  else:
                      weighting = space.weighting
  
                  return type(space)(newshape, space.dtype, weighting=weighting)
  
              def __repr__(self):
                  """Return ``repr(self)``."""
                  return repr(space) + '.byaxis'
  
          return NpyTensorSpacebyaxis()
docs: Return the subspace defined along one or several dimensions.
  
          Examples
          --------
          Indexing with integers or slices:
  
          >>> space = odl.rn((2, 3, 4))
          >>> space.byaxis[0]
          rn(2)
          >>> space.byaxis[1:]
          rn((3, 4))
  
          Lists can be used to stack spaces arbitrarily:
  
          >>> space.byaxis[[2, 1, 2]]
          rn((4, 3, 4))