11 flat_var = var.flatten()
12 flat_nbroadcast = np.repeat(nbroadcast, var.counts)
14 flat_var_repeat = np.repeat(flat_var, flat_nbroadcast)
17 reindex = np.hstack([np.add.outer(np.arange(0, var.counts[i]) * nbroadcast[i], np.arange(0, nbroadcast[i])).flatten(
"F")
for i
in range(len(nbroadcast))])
19 reindex += np.repeat(np.hstack([[0], np.cumsum(nbroadcast * var.counts)[:-1]]), nbroadcast * var.counts)
20 flat_var_repeat_ordered = flat_var_repeat[reindex]
21 return group(flat_var_repeat_ordered, np.repeat(var.counts, nbroadcast))