I'm trying to create an efficient function for re-sampling timeseries data.
Assumption: Both sets of timeseries data have the same start and end time. (I do this in a separate step.)
Resample function (ineffecient)
import numpy as np
def resample(desired_time_sequence, data_sequence):
downsampling_indices = np.linspace(0, len(data_sequence)-1, len(desired_sequence)).round().astype(int)
downsampled_array = [data_sequence[ind] for ind in downsampling_indices]
return downsampled_array
Speed testing
import testit
def test_speed(): resample([1,2,3], [.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6])
print(tesit.testit(test_speed, number=100000)
# 1.5003695999998854
Interested to hear any suggestions
Aucun commentaire:
Enregistrer un commentaire