NumPy | logspace method
Start your free 7-days trial now!
Numpy's logspace(~)
method creates a Numpy array with values that are evenly spaced in a log-scale.
Parameters
1. start
| number
The starting value of the Numpy array.
2. stop
| number
The ending value of the Numpy array. This is inclusive.
3. num
| int
| optional
The number of samples you want to generate. By default, num=50
.
4. endpoint
| boolean
| optional
If set to True
, then stop will be the last value of the Numpy array. By default, endpoint=False
.
5. base
| float
| optional
The base of the logarithm to use. By default, base=10.
6. dtype
| string
or type
| optional
The desired data type for the Numpy array. This overrides the default behaviour of using the same data-type as the source array.
Return value
A Numpy array with values that are evenly spaced in a log-scale.
Examples
Basic Usage
np.logspace(2, 5, 4)
array([ 100., 1000., 10000., 100000.])
Here, the numbers in the array are generated like so:
[0] 10^2 = 100[1] 10^3 = 1000[2] 10^4 = 10000[3] 10^5 = 100000
Excluding the endpoint
We set endpoint=False
, like follows:
np.logspace(2,5,4, endpoint=False)
array([ 100. , 562.34132519, 3162.27766017, 17782.79410039])
Explicit typing
We set dtype=float
to obtain a Numpy array of type float.
np.logspace(2,5,4, dtype=float)
array([ 100., 1000., 10000., 100000.])