def svd_flip(u, v, u_based_decision=True):
 if u_based_decision:
  max_abs_cols = np.argmax(np.abs(u), axis=0)
  signs = np.sign(u[(max_abs_cols, xrange(u.shape[1]))])
  u *= signs
  v *= signs[:, np.newaxis]
 else:
  max_abs_rows = np.argmax(np.abs(v), axis=1)
  signs = np.sign(v[(xrange(v.shape[0]), max_abs_rows)])
  u *= signs
  v *= signs[:, np.newaxis]
 return (u, v)

def svd_flip ( u , v , u_based_decision = True ) : if u_based_decision : max_abs_cols = np . argmax ( np . abs ( u ) , axis = 0 ) signs = np . sign ( u [ ( max_abs_cols , xrange ( u . shape [ 1 ] ) ) ] ) u *= signs v *= signs [ : , np . newaxis ] else : max_abs_rows = np . argmax ( np . abs ( v ) , axis = 1 ) signs = np . sign ( v [ ( xrange ( v . shape [ 0 ] ) , max_abs_rows ) ] ) u *= signs v *= signs [ : , np . newaxis ] return ( u , v )
sign correction to ensure deterministic output from svd .