Home > Net >  How to downsample a 1d array numpy array exponentially
How to downsample a 1d array numpy array exponentially

Time:03-02

I have a 1-d numpy array which I would like to down sample with a exponential distribution. Currently, I am using signal.resample(y,downsize) for a uniform re-sample. Not sure if there is a quick way to do this but exponentially

enter image description here

from scipy import signal

# uniform resample example
x = np.arange(100)    
y = np.sin(x)
linear_resample = signal.resample(y,15)

CodePudding user response:

import numpy as np
np.random.seed(73)


# a random array of integers of length 100
arr_test = np.random.randint(300, size=100)
print(arr_test)

# lets divide 0 to 100 in exponential fashion
ls = np.logspace(0.00001, 2, num=100, endpoint=False, base=10.0).astype(np.int32)
print(ls)
# sample the array
arr_samp = arr_test[ls]
print(arr_samp)

I have use log base 10. You can change to natural if you want.

  • Related