Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numbers logarithmically spaced between two floats in numpy

Tags:

python

numpy

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.

like image 424
Dexter Avatar asked Sep 25 '15 14:09

Dexter


1 Answers

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)
like image 142
Warren Weckesser Avatar answered Oct 22 '22 05:10

Warren Weckesser