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.

Revisions

  1. asifr revised this gist Dec 6, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions resample.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    import numpy as np

    def resample(x, t, start, end, step):
    bins = np.arange(start, end+step, step)
    inds = np.digitize(t,bins)
  2. asifr revised this gist Dec 5, 2020. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions resample.py
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,13 @@
    def resample(x, t, start, end, step):
    bins = np.arange(start, end+step, step)
    inds = np.digitize(t,bins)
    y = np.empty(len(bins)) * np.nan
    y[inds] = x
    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)
  3. asifr created this gist Dec 5, 2020.
    10 changes: 10 additions & 0 deletions resample.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    def resample(x, t, start, end, step):
    bins = np.arange(start, end+step, step)
    inds = np.digitize(t,bins)
    y = np.empty(len(bins)) * np.nan
    y[inds] = x
    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)