Reputation: 2164
I have an array of some arbitrary data x
and associated timestamps t
that correspond to the data in x
(they are the same length N
).
I want to downsample my data x
to a smaller length M < N
, such that the new data is roughly equally spaced in time (by using the timestamp information). This would be instead of simply decimating the data by taking every nth datapoint. Using the closest time-neighbor is fine.
scipy has some resampling code, but it actually tries to interpolate between data points, which I cannot do for my data. Does numpy or scipy have code that does this?
For example, suppose I want to downsample the letters of the alphabet according to some logarithmic time:
import string
import numpy as np
x = string.lowercase[::]
t = np.logspace(1, 10, num=26)
y = downsample(x, t, 8)
Upvotes: 0
Views: 1169
Reputation: 31060
I'd suggest using pandas
, specifically the resample
function:
Convenience method for frequency conversion and resampling of regular time-series data.
Note the how
parameter in particular.
You can convert your numpy array to a DataFrame:
import pandas as pd
YourPandasDF = pd.DataFrame(YourNumpyArray)
Upvotes: 1