I’m looking for a function like range except that the step is a fraction of the previous number generated. So if the fraction was 99/100 the set of numbers might be something like this: 100, 99, 98.01… 0.001
Would this be more efficiently done with a for-loop and range-like function or with just a while-loop?
The code I have so far:
JavaScript
x
6
1
stop = .001
2
current = 100
3
while current > stop:
4
#code
5
current *= 0.99
6
Advertisement
Answer
You can use np.geomspace
:
JavaScript
1
2
1
np.geomspace(100, 12.5, 4)
2
You can use np.arange
with direct exponentiation:
JavaScript
1
2
1
12.5 * 2**np.arange(3, -1, -1)
2
np.logspace
is also an option:
JavaScript
1
2
1
100 * np.logspace(0, -3, 4, base=2)
2