Numpy linspace returns evenly spaced numbers over a specified interval. Numpy logspace return numbers spaced evenly on a log scale.
I don\'t understand why numpy log
From documentation for numpy.logspace() -
numpy.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None)
Return numbers spaced evenly on a log scale.
In linear space, the sequence starts at base ** start (base to the power of start) and ends with base ** stop (see endpoint below).
For your case, base is defaulting to 10, so its going from 10 raised to 0.02 to 10 raised to 2 (100).
2017 update: The numpy 1.12 includes a function that does exactly what the original question asked, i.e. returns a range between two values evenly sampled in log space.
The function is numpy.geomspace
>>> np.geomspace(0.02, 2.0, 20)
array([ 0.02 , 0.0254855 , 0.03247553, 0.04138276, 0.05273302,
0.06719637, 0.08562665, 0.1091119 , 0.13903856, 0.17717336,
0.22576758, 0.28768998, 0.36659614, 0.46714429, 0.59527029,
0.75853804, 0.96658605, 1.23169642, 1.56951994, 2. ])
logspace
computes its start and end points as base**start
and base**stop
respectively. The base
value can be specified, but is 10.0 by default.
For your example you have a start value of 10**0.02 == 1.047
and a stop value of 10**2 == 100
.
You could use the following parameters (calculated with np.log10
) instead:
>>> np.logspace(np.log10(0.02) , np.log10(2.0) , num=20)
array([ 0.02 , 0.0254855 , 0.03247553, 0.04138276, 0.05273302,
0.06719637, 0.08562665, 0.1091119 , 0.13903856, 0.17717336,
0.22576758, 0.28768998, 0.36659614, 0.46714429, 0.59527029,
0.75853804, 0.96658605, 1.23169642, 1.56951994, 2. ])
This is pretty simple.
NumPy gives you numbers evenly distributed in log space.
i.e. 10^(value). where value is evenly spaced between your start and stop values.
You'll note 10^0.02 is 1.04712 ... and 10^2 is 100