def check_index(ind, dimension):
 if isinstance(ind, list):
  x = np.array(ind)
  if ((x >= dimension).any() or (x <= (- dimension)).any()):
   raise IndexError(('Index out of bounds %s' % dimension))
 elif isinstance(ind, slice):
  return
 elif (ind >= dimension):
  raise IndexError(('Index is not smaller than dimension %d >= %d' % (ind, dimension)))
 elif (ind < (- dimension)):
  msg = 'Negative index is not greater than negative dimension %d <= -%d'
  raise IndexError((msg % (ind, dimension)))

def check_index ( ind , dimension ) : if isinstance ( ind , list ) : x = np . array ( ind ) if ( ( x >= dimension ) . any ( ) or ( x <= ( - dimension ) ) . any ( ) ) : raise IndexError ( ( 'Index out of bounds %s' % dimension ) ) elif isinstance ( ind , slice ) : return elif ( ind >= dimension ) : raise IndexError ( ( 'Index is not smaller than dimension %d >= %d' % ( ind , dimension ) ) ) elif ( ind < ( - dimension ) ) : msg = 'Negative index is not greater than negative dimension %d <= -%d' raise IndexError ( ( msg % ( ind , dimension ) ) )
check validity of index for a given dimension examples .