Logarithmic visualization ranges
Create tick values spanning several orders of magnitude for plots or axes.
NumPy · Function
Generates values evenly spaced in logarithmic space. It samples exponents from start to stop and raises base to those exponents.
logspace samples a linear interval between start and stop, then raises the chosen base to those sampled powers. By default it returns 50 values and includes the value at stop; axis controls where dimensions from array-like inputs are inserted.
numpy.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None, axis=0)| Name | Type | Description |
|---|---|---|
start | array_like | Starting exponent of the sequence. |
stop | array_like | Ending exponent of the sequence. |
num | integer, optional | Number of samples to generate; defaults to 50. |
endpoint | boolean, optional | Whether stop is included as the final sample; defaults to True. |
base | array_like, optional | Base of the logarithmic space; defaults to 10.0. |
dtype | dtype, optional | Output data type. |
axis | integer, optional | Axis where dimensions of array-like inputs are inserted; defaults to 0. |
ndarray
logspace when multiplicative rather than additive spacing is needed.base ** start.base ** stop.num controls output length and defaults to 50.endpoint=True includes the upper bound.base can be changed from its default to define another logarithmic scale.dtype unset lets NumPy infer the output type from the bounds; specify it when a particular type is required.import numpy as np
values = np.logspace(0, 3, num=4)
print(values) # [ 1. 10. 100. 1000.]Creates four values whose base-10 logarithms are evenly spaced from 0 through 3.
Create tick values spanning several orders of magnitude for plots or axes.
Evaluate an algorithm at geometrically increasing parameter values.
Construct frequency, size, or tolerance grids where ratios matter more than differences.
numpy.logspace generate?It returns values evenly spaced on a logarithmic scale. Internally, the exponents are evenly spaced from start to stop, and the returned values are base raised to those exponents.
Follow-up: How would you omit the final endpoint? Pass endpoint=False, which excludes stop from the exponent sequence.
base?base determines the logarithm base used for the spacing, with a default of 10. The endpoints in the returned value space are base ** start and, by default, base ** stop.
Follow-up: What happens with a different base, such as 2? The same exponent interval is used, but each exponent is applied to 2 instead of 10.
num and endpoint affect the output?num specifies how many samples are generated and defaults to 50. endpoint=True includes the final bound, while setting it to false excludes that bound.
Follow-up: Which parameter controls placement of dimensions for array-like bounds? axis selects the axis where the new sample dimension is inserted.
numpy.linspacenumpy.geomspace