def _structured_bootstrap(args, n_boot, units, func, func_kwargs, rs):
 unique_units = np.unique(units)
 n_units = len(unique_units)
 args = [[a[(units == unit)] for unit in unique_units] for a in args]
 boot_dist = []
 for i in range(int(n_boot)):
  resampler = rs.randint(0, n_units, n_units)
  sample = [np.take(a, resampler, axis=0) for a in args]
  lengths = map(len, sample[0])
  resampler = [rs.randint(0, n, n) for n in lengths]
  sample = [[c.take(r, axis=0) for (c, r) in zip(a, resampler)] for a in sample]
  sample = list(map(np.concatenate, sample))
  boot_dist.append(func(*sample, **func_kwargs))
 return np.array(boot_dist)

def _structured_bootstrap ( args , n_boot , units , func , func_kwargs , rs ) : unique_units = np . unique ( units ) n_units = len ( unique_units ) args = [ [ a [ ( units == unit ) ] for unit in unique_units ] for a in args ] boot_dist = [ ] for i in range ( int ( n_boot ) ) : resampler = rs . randint ( 0 , n_units , n_units ) sample = [ np . take ( a , resampler , axis = 0 ) for a in args ] lengths = map ( len , sample [ 0 ] ) resampler = [ rs . randint ( 0 , n , n ) for n in lengths ] sample = [ [ c . take ( r , axis = 0 ) for ( c , r ) in zip ( a , resampler ) ] for a in sample ] sample = list ( map ( np . concatenate , sample ) ) boot_dist . append ( func ( * sample , ** func_kwargs ) ) return np . array ( boot_dist )
resample units instead of datapoints .