def random_rot(dim):
 H = eye(dim)
 D = ones((dim,))
 for n in range(1, dim):
  x = normal(size=(((dim - n) + 1),))
  D[(n - 1)] = sign(x[0])
  x[0] -= (D[(n - 1)] * sqrt((x * x).sum()))
  Hx = (eye(((dim - n) + 1)) - ((2.0 * outer(x, x)) / (x * x).sum()))
  mat = eye(dim)
  mat[(n - 1):, (n - 1):] = Hx
  H = dot(H, mat)
 D[(-1)] = (- D.prod())
 H = (D * H.T).T
 return H

def random_rot ( dim ) : H = eye ( dim ) D = ones ( ( dim , ) ) for n in range ( 1 , dim ) : x = normal ( size = ( ( ( dim - n ) + 1 ) , ) ) D [ ( n - 1 ) ] = sign ( x [ 0 ] ) x [ 0 ] -= ( D [ ( n - 1 ) ] * sqrt ( ( x * x ) . sum ( ) ) ) Hx = ( eye ( ( ( dim - n ) + 1 ) ) - ( ( 2.0 * outer ( x , x ) ) / ( x * x ) . sum ( ) ) ) mat = eye ( dim ) mat [ ( n - 1 ) : , ( n - 1 ) : ] = Hx H = dot ( H , mat ) D [ ( - 1 ) ] = ( - D . prod ( ) ) H = ( D * H . T ) . T return H
return a random rotation matrix .