def _iter_contrasts(n_subjects, factor_levels, effect_picks):
 from scipy.signal import detrend
 sc = []
 n_factors = len(factor_levels)
 for n_levels in factor_levels:
  sc.append([np.ones([n_levels, 1]), detrend(np.eye(n_levels), type='constant')])
 for this_effect in effect_picks:
  contrast_idx = _get_contrast_indices((this_effect + 1), n_factors)
  c_ = sc[0][contrast_idx[(n_factors - 1)]]
  for i_contrast in range(1, n_factors):
   this_contrast = contrast_idx[((n_factors - 1) - i_contrast)]
   c_ = np.kron(c_, sc[i_contrast][this_contrast])
  df1 = np.linalg.matrix_rank(c_)
  df2 = (df1 * (n_subjects - 1))
  (yield (c_, df1, df2))

def _iter_contrasts ( n_subjects , factor_levels , effect_picks ) : from scipy . signal import detrend sc = [ ] n_factors = len ( factor_levels ) for n_levels in factor_levels : sc . append ( [ np . ones ( [ n_levels , 1 ] ) , detrend ( np . eye ( n_levels ) , type = 'constant' ) ] ) for this_effect in effect_picks : contrast_idx = _get_contrast_indices ( ( this_effect + 1 ) , n_factors ) c_ = sc [ 0 ] [ contrast_idx [ ( n_factors - 1 ) ] ] for i_contrast in range ( 1 , n_factors ) : this_contrast = contrast_idx [ ( ( n_factors - 1 ) - i_contrast ) ] c_ = np . kron ( c_ , sc [ i_contrast ] [ this_contrast ] ) df1 = np . linalg . matrix_rank ( c_ ) df2 = ( df1 * ( n_subjects - 1 ) ) ( yield ( c_ , df1 , df2 ) )
setup contrasts .