python - Making a faster wavelet transform/Appending data faster -
i taking 1-d wavelet transform of data. how can make faster? have 1.4 million samples , 32 features.
def apply_wavelet_transform(data): ca,cd=pywt.dwt(data[0,:],'haar') in range(1,data.shape[0]): ca_i,__=pywt.dwt(data[i,:],'haar') ca=np.vstack((ca,ca_i)) return ca
consider don't care memory usage as speed of execution.
this common mistake. don't want append rows array 1 @ time, because each iteration requires copying entire array. complexity: o(n**2). better keep intermediate results in list , form array @ end. better because lists not require elements contiguous in memory, no copying required.
def apply_wavelet_transform(data): results_list = [] row in data: ca, cd = pywt.dwt(row, 'haar') results_list.append(ca) result = np.array(results_list) return result
Comments
Post a Comment