Skip to content
Advertisement

Using a for-loop and range function vs a while-loop

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

Advertisement

Answer

You can use np.geomspace:

JavaScript

You can use np.arange with direct exponentiation:

JavaScript

np.logspace is also an option:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement