13

I am trying to get 1000 numbers logarithmically spaced between two floats (say between 0.674 to 100.0) using python. Purpose of this was to get more numbers closer to 0.674 and after than just few large numbers near 100. I tried using 'numpy.logspace' function like following

NumberRange = np.logspace(0.674, 100.0, num=1000)

But it was giving result with these numbers as exponents. I want numbers between two floats but spaced logarithmically.

I have already checked this post but it was confusing.

Community
  • 1
  • 1
Dexter
  • 1,421
  • 3
  • 22
  • 43

1 Answers1

34

The first two arguments of numpy.logspace are the exponents of the limits. Use

NumberRange = np.logspace(np.log10(0.674), np.log10(100.0), num=1000)

Recent versions of NumPy have the function geomspace, which takes the values of the endpoints rather than their logarithms:

NumberRange = np.geomspace(0.674, 100.0, num=1000)
Warren Weckesser
  • 110,654
  • 19
  • 194
  • 214
  • Thank you. I was wondering how to do this if you want points on log scale from 0 to 1 (including 0)? Is it possible ? – Dexter Sep 28 '15 at 05:54
  • log(0) is undefined, you can draw an arrow to represent -inf –  Oct 05 '18 at 11:41