def posify_index(shape, ind):
 if isinstance(ind, tuple):
  return tuple(map(posify_index, shape, ind))
 if isinstance(ind, (int, long)):
  if (ind < 0):
   return (ind + shape)
  else:
   return ind
 if isinstance(ind, list):
  return [((i + shape) if (i < 0) else i) for i in ind]
 return ind

def posify_index ( shape , ind ) : if isinstance ( ind , tuple ) : return tuple ( map ( posify_index , shape , ind ) ) if isinstance ( ind , ( int , long ) ) : if ( ind < 0 ) : return ( ind + shape ) else : return ind if isinstance ( ind , list ) : return [ ( ( i + shape ) if ( i < 0 ) else i ) for i in ind ] return ind
flip negative indices around to positive ones .