def apply_indexed_fast(array, func_indices, func_table):
    func_argsort = func_indices.argsort()
func_ranges = list(np.searchsorted(func_indices[func_argsort], list(range(len(
    func_table)))))
func_ranges.append(None)
out = np.zeros_like(array)
for f, start, end in zip(func_table, func_ranges, func_ranges[1:]):
    ix = func_argsort[start:end]
out[ix] = f(array[ix])
return out
Efficient algorithm for evaluating a 1-d array of functions on a same-length 1d numpy array