Skip to content

Instantly share code, notes, and snippets.

@asifr
Last active December 6, 2020 06:19
Show Gist options
  • Save asifr/d77a1725c47115a1f400c7231f6c9c97 to your computer and use it in GitHub Desktop.
Save asifr/d77a1725c47115a1f400c7231f6c9c97 to your computer and use it in GitHub Desktop.
Resample a numpy array
import numpy as np
def resample(x, t, start, end, step):
bins = np.arange(start, end+step, step)
inds = np.digitize(t,bins)
n = x.shape[0]
y = np.empty((n, len(bins))) * np.nan
for i in range(n):
y[i,inds[i,:]] = x[i,:]
return y, bins
x = [3,6,9,12,15,18,21,24]
t = [0,4,8,10,45,67,78,90]
x_re, t_re = resample(x, t, 0, 100, 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment