def ts_stats_significance(ts, ts_stat_func, null_ts_func, B=<NUM_LIT:1000>, permute_fast=False):
stats_ts = ts_stat_func(ts)<EOL>if permute_fast:<EOL><INDENT>null_ts = list(map(np.random.permutation, np.array([ts, ] * B)))<EOL><DEDENT>else:<EOL><INDENT>null_ts = np.vstack([null_ts_func(ts) for i in np.arange(<NUM_LIT:0>, B)])<EOL><DEDENT>stats_null_ts = np.vstack([ts_stat_func(nts) for nts in null_ts])<EOL>pvals = []<EOL>nums = []<EOL>for i in np.arange(<NUM_LIT:0>, len(stats_ts)):<EOL><INDENT>num_samples = np.sum((stats_null_ts[:, i] >= stats_ts[i]))<EOL>nums.append(num_samples)<EOL>pval = num_samples / float(B)<EOL>pvals.append(pval)<EOL><DEDENT>return stats_ts, pvals, nums<EOL>
Compute  the statistical significance of a test statistic at each point
        of the time series.