def dummy_nested(d1, d2, method='full'):
 if (method == 'full'):
  return d2
 (start1, end1) = dummy_limits(d1)
 (start2, end2) = dummy_limits(d2)
 first = np.in1d(start2, start1)
 last = np.in1d(end2, end1)
 equal = (first == last)
 col_dropf = ((~ first) * (~ equal))
 col_dropl = ((~ last) * (~ equal))
 if (method == 'drop-last'):
  d12rl = dummy_product(d1[:, :(-1)], d2[:, :(-1)])
  dd = np.column_stack((np.ones(d1.shape[0], int), d1[:, :(-1)], d2[:, col_dropl]))
 elif (method == 'drop-first'):
  d12r = dummy_product(d1[:, 1:], d2[:, 1:])
  dd = np.column_stack((np.ones(d1.shape[0], int), d1[:, 1:], d2[:, col_dropf]))
 else:
  raise ValueError('method not recognized')
 return (dd, col_dropf, col_dropl)

def dummy_nested ( d1 , d2 , method = 'full' ) : if ( method == 'full' ) : return d2 ( start1 , end1 ) = dummy_limits ( d1 ) ( start2 , end2 ) = dummy_limits ( d2 ) first = np . in1d ( start2 , start1 ) last = np . in1d ( end2 , end1 ) equal = ( first == last ) col_dropf = ( ( ~ first ) * ( ~ equal ) ) col_dropl = ( ( ~ last ) * ( ~ equal ) ) if ( method == 'drop-last' ) : d12rl = dummy_product ( d1 [ : , : ( - 1 ) ] , d2 [ : , : ( - 1 ) ] ) dd = np . column_stack ( ( np . ones ( d1 . shape [ 0 ] , int ) , d1 [ : , : ( - 1 ) ] , d2 [ : , col_dropl ] ) ) elif ( method == 'drop-first' ) : d12r = dummy_product ( d1 [ : , 1 : ] , d2 [ : , 1 : ] ) dd = np . column_stack ( ( np . ones ( d1 . shape [ 0 ] , int ) , d1 [ : , 1 : ] , d2 [ : , col_dropf ] ) ) else : raise ValueError ( 'method not recognized' ) return ( dd , col_dropf , col_dropl )
unfinished and incomplete mainly copy past dummy_product dummy variable from product of two dummy variables parameters d1 .