<s> from pylab import * <EOL> import sklearn <EOL> import sklearn . preprocessing <EOL> def cross_product_left_term_matrix_from_vector ( a ) : <EOL> return matrix ( [ [ <NUM_LIT:0> , - a [ <NUM_LIT:2> ] , a [ <NUM_LIT:1> ] ] , [ a [ <NUM_LIT:2> ] , <NUM_LIT:0> , - a [ <NUM_LIT:0> ] ] , [ - a [ <NUM_LIT:1> ] , a [ <NUM_LIT:0> ] , <NUM_LIT:0> ] ] ) <EOL> def project_vectors_onto_vectors ( a , b , axis = <NUM_LIT:1> ) : <EOL> assert axis == <NUM_LIT:0> or axis == <NUM_LIT:1> <EOL> a = matrix ( a , dtype ( float64 ) ) <EOL> b = matrix ( b , dtype ( float64 ) ) <EOL> if axis == <NUM_LIT:0> : <EOL> a = a . T <EOL> b = b . T <EOL> b_normalized = matrix ( sklearn . preprocessing . normalize ( b ) ) <EOL> a_scalar = a * b_normalized . T <EOL> if a . shape == b . shape : <EOL> a_scalar = matrix ( diag ( a_scalar ) ) <EOL> if a_scalar . shape [ <NUM_LIT:0> ] == <NUM_LIT:1> : <EOL> a_scalar_column = a_scalar . T <EOL> else : <EOL> a_scalar_column = a_scalar <EOL> if a . shape == b . shape : <EOL> a_projection = matrix ( a_scalar_column . A * b_normalized . A ) <EOL> a_orthogonal = a - a_projection <EOL> else : <EOL> a_projection = matrix ( a_scalar_column . A * tile ( b_normalized , ( a_scalar . shape [ <NUM_LIT:0> ] , <NUM_LIT:1> ) ) . A ) <EOL> a_orthogonal = a - a_projection <EOL> if axis == <NUM_LIT:0> : <EOL> a_projection = a_projection . T <EOL> a_orthogonal = a_orthogonal . T <EOL> return a_projection , a_orthogonal </s>
