小波并行计算

时间:2019-02-09 21:22:34

标签: multithreading multiprocessing

我想使用并行工作来加快我的代码的速度。 我该如何并行处理以下代码:

sample_size = 800000
# ts_std is a signal in the form of a pandas series
def transform_ts(ts_std, n_dim=160):
    # bucket or chunk size, 5000 in this case (800000 / 160)
    bucket_size = int(sample_size / n_dim)
    # new_ts will be the container of the new data
    new_ts = []
    # this for iteract any chunk/bucket until reach the whole sample_size (800000)
    for i in range(0, sample_size, bucket_size):
        # cut each bucket to ts_range
        ts_range = ts_std[i:i + bucket_size]
        # calculate each feature
        wavelets, _ = pywt.cwt(ts_range.values, np.arange(wavelet_width_min, wavelet_width_max + 1), wav)
        wav_avgs = np.mean(wavelets, axis=1)
        new_ts.append(wav_avgs)
    return new_ts

0 个答案:

没有答案