Skip to main content
Code Review

Return to Question

Commonmark migration
Source Link

I'm trying to create an efficient function for re-sampling time-series data.

Assumption: Both sets of time-series data have the same start and end time. (I do this in a separate step.)

#Resample function (inefficient)

Resample function (inefficient)

import numpy as np
def resample(desired_time_sequence, data_sequence):
 downsampling_indices = np.linspace(0, len(data_sequence)-1, len(desired_time_sequence)).round().astype(int)
 downsampled_array = [data_sequence[ind] for ind in downsampling_indices] 
 return downsampled_array

##Speed testing

Speed testing

import timeit
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(timeit.timeit(test_speed, number=100000))
# 1.5003695999998854 

Interested to hear any suggestions.

I'm trying to create an efficient function for re-sampling time-series data.

Assumption: Both sets of time-series data have the same start and end time. (I do this in a separate step.)

#Resample function (inefficient)

import numpy as np
def resample(desired_time_sequence, data_sequence):
 downsampling_indices = np.linspace(0, len(data_sequence)-1, len(desired_time_sequence)).round().astype(int)
 downsampled_array = [data_sequence[ind] for ind in downsampling_indices] 
 return downsampled_array

##Speed testing

import timeit
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(timeit.timeit(test_speed, number=100000))
# 1.5003695999998854 

Interested to hear any suggestions.

I'm trying to create an efficient function for re-sampling time-series data.

Assumption: Both sets of time-series data have the same start and end time. (I do this in a separate step.)

Resample function (inefficient)

import numpy as np
def resample(desired_time_sequence, data_sequence):
 downsampling_indices = np.linspace(0, len(data_sequence)-1, len(desired_time_sequence)).round().astype(int)
 downsampled_array = [data_sequence[ind] for ind in downsampling_indices] 
 return downsampled_array

Speed testing

import timeit
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(timeit.timeit(test_speed, number=100000))
# 1.5003695999998854 

Interested to hear any suggestions.

Syntax error in code
Source Link

I'm trying to create an efficient function for re-sampling time-series data.

Assumption: Both sets of time-series data have the same start and end time. (I do this in a separate step.)

#Resample function (inefficient)

import numpy as np
def resample(desired_time_sequence, data_sequence):
 downsampling_indices = np.linspace(0, len(data_sequence)-1, len(desired_sequencedesired_time_sequence)).round().astype(int)
 downsampled_array = [data_sequence[ind] for ind in downsampling_indices] 
 return downsampled_array

##Speed testing

import testittimeit
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(tesittimeit.testittimeit(test_speed, number=100000))
# 1.5003695999998854 

Interested to hear any suggestions.

I'm trying to create an efficient function for re-sampling time-series data.

Assumption: Both sets of time-series data have the same start and end time. (I do this in a separate step.)

#Resample function (inefficient)

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.

I'm trying to create an efficient function for re-sampling time-series data.

Assumption: Both sets of time-series data have the same start and end time. (I do this in a separate step.)

#Resample function (inefficient)

import numpy as np
def resample(desired_time_sequence, data_sequence):
 downsampling_indices = np.linspace(0, len(data_sequence)-1, len(desired_time_sequence)).round().astype(int)
 downsampled_array = [data_sequence[ind] for ind in downsampling_indices] 
 return downsampled_array

##Speed testing

import timeit
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(timeit.timeit(test_speed, number=100000))
# 1.5003695999998854 

Interested to hear any suggestions.

title
Link
dfhwze
  • 14.1k
  • 3
  • 40
  • 101

Efficiently resample Efficient resampling of time series in python

Edited grammar, punctuation and edited tags.
Source Link
Loading
Source Link
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /