def roll(x, shift, axis=None):
 if (axis is None):
  if (x.ndim > 1):
   y = x.flatten()
   return roll(y, shift, axis=0).reshape(x.shape)
  else:
   axis = 0
 if (axis < 0):
  axis += x.ndim
 shift = (shift % x.shape[axis])
 allslice = slice(None)
 front_slice = slice((- shift), None)
 front_list = ((([allslice] * axis) + [front_slice]) + ([allslice] * ((x.ndim - axis) - 1)))
 end_slice = slice(0, (- shift))
 end_list = ((([allslice] * axis) + [end_slice]) + ([allslice] * ((x.ndim - axis) - 1)))
 return join(axis, x.__getitem__(tuple(front_list)), x.__getitem__(tuple(end_list)))

def roll ( x , shift , axis = None ) : if ( axis is None ) : if ( x . ndim > 1 ) : y = x . flatten ( ) return roll ( y , shift , axis = 0 ) . reshape ( x . shape ) else : axis = 0 if ( axis < 0 ) : axis += x . ndim shift = ( shift % x . shape [ axis ] ) allslice = slice ( None ) front_slice = slice ( ( - shift ) , None ) front_list = ( ( ( [ allslice ] * axis ) + [ front_slice ] ) + ( [ allslice ] * ( ( x . ndim - axis ) - 1 ) ) ) end_slice = slice ( 0 , ( - shift ) ) end_list = ( ( ( [ allslice ] * axis ) + [ end_slice ] ) + ( [ allslice ] * ( ( x . ndim - axis ) - 1 ) ) ) return join ( axis , x . __getitem__ ( tuple ( front_list ) ) , x . __getitem__ ( tuple ( end_list ) ) )
convenience function to roll tensortypes along the given axis .