def contrastfromcols(L, D, pseudo=None):
 L = np.asarray(L)
 D = np.asarray(D)
 (n, p) = D.shape
 if ((L.shape[0] != n) and (L.shape[1] != p)):
  raise ValueError('shape of L and D mismatched')
 if (pseudo is None):
  pseudo = np.linalg.pinv(D)
 if (L.shape[0] == n):
  C = np.dot(pseudo, L).T
 else:
  C = L
  C = np.dot(pseudo, np.dot(D, C.T)).T
 Lp = np.dot(D, C.T)
 if (len(Lp.shape) == 1):
  Lp.shape = (n, 1)
 if (np_matrix_rank(Lp) != Lp.shape[1]):
  Lp = fullrank(Lp)
  C = np.dot(pseudo, Lp).T
 return np.squeeze(C)

def contrastfromcols ( L , D , pseudo = None ) : L = np . asarray ( L ) D = np . asarray ( D ) ( n , p ) = D . shape if ( ( L . shape [ 0 ] != n ) and ( L . shape [ 1 ] != p ) ) : raise ValueError ( 'shape of L and D mismatched' ) if ( pseudo is None ) : pseudo = np . linalg . pinv ( D ) if ( L . shape [ 0 ] == n ) : C = np . dot ( pseudo , L ) . T else : C = L C = np . dot ( pseudo , np . dot ( D , C . T ) ) . T Lp = np . dot ( D , C . T ) if ( len ( Lp . shape ) == 1 ) : Lp . shape = ( n , 1 ) if ( np_matrix_rank ( Lp ) != Lp . shape [ 1 ] ) : Lp = fullrank ( Lp ) C = np . dot ( pseudo , Lp ) . T return np . squeeze ( C )
from an n x p design matrix d and a matrix l .