def dummy_limits(d):
 (nobs, nvars) = d.shape
 (start1, col1) = np.nonzero((np.diff(d, axis=0) == 1))
 (end1, col1_) = np.nonzero((np.diff(d, axis=0) == (-1)))
 cc = np.arange(nvars)
 if ((not (np.r_[([0], col1)] == cc).all()) or (not (np.r_[(col1_, [(nvars - 1)])] == cc).all())):
  raise ValueError('dummy variable is not sorted')
 start = np.r_[([0], (start1 + 1))]
 end = np.r_[((end1 + 1), [nobs])]
 return (start, end)

def dummy_limits ( d ) : ( nobs , nvars ) = d . shape ( start1 , col1 ) = np . nonzero ( ( np . diff ( d , axis = 0 ) == 1 ) ) ( end1 , col1_ ) = np . nonzero ( ( np . diff ( d , axis = 0 ) == ( - 1 ) ) ) cc = np . arange ( nvars ) if ( ( not ( np . r_ [ ( [ 0 ] , col1 ) ] == cc ) . all ( ) ) or ( not ( np . r_ [ ( col1_ , [ ( nvars - 1 ) ] ) ] == cc ) . all ( ) ) ) : raise ValueError ( 'dummy variable is not sorted' ) start = np . r_ [ ( [ 0 ] , ( start1 + 1 ) ) ] end = np . r_ [ ( ( end1 + 1 ) , [ nobs ] ) ] return ( start , end )
start and endpoints of groups in a sorted dummy variable array helper function for nested categories examples .