Reputation: 243
I have a numpy array representing magnitudes of a fourier transform, and I want to resample it logarithmically:
Lets say it was from 100hz to 10khz, and each bucket was 100hz, I want to take that discrete distribution, create a continuous distribution, and then resample that continuous distribution logarithmically (i.e. bucket 1 is 100hz to 200hz, bucket 2 is 200hz to 400hz, etc (not specifically doubling, but for any logarithmic base)).
I can definitely conceive of a manual way to do this, but I'm absolutely sure that there is a far more pythonic way of doing this in like 2 lines (and I bet you can configure even the interpolation method (linear, logarithmic, parabolic, etc), maybe even as part of numpy).
Upvotes: 2
Views: 383
Reputation: 646
A possible implementation is given below. The logspace()
routine from numpy creates the bucket boundaries and I subsequently draw a random index.
import random
import numpy as np
NumberOfBuckets = 10
LogGrid = np.logspace(2.0, 4.0, num=NumberOfBuckets) % 10^2 to 10^4
IntDraw = random.randint(0,NumberOfBuckets-1)
RandomInterval = [LogGrid[IntDraw], LogGrid[IntDraw+1]]
print(RandomInterval)
Upvotes: 2