Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

NumPy · Function

np.logspace

Generates values evenly spaced in logarithmic space. It samples exponents from start to stop and raises base to those exponents.

How it works

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.

Syntax

numpy.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None, axis=0)

Parameters

NameTypeDescription
startarray_likeStarting exponent of the sequence.
stoparray_likeEnding exponent of the sequence.
numinteger, optionalNumber of samples to generate; defaults to 50.
endpointboolean, optionalWhether stop is included as the final sample; defaults to True.
basearray_like, optionalBase of the logarithmic space; defaults to 10.0.
dtypedtype, optionalOutput data type.
axisinteger, optionalAxis where dimensions of array-like inputs are inserted; defaults to 0.

Returns

ndarray

Key points

  • Use logspace when multiplicative rather than additive spacing is needed.
  • The first returned value is base ** start.
  • With the default endpoint behavior, the last value is base ** stop.
  • num controls output length and defaults to 50.
  • The default endpoint=True includes the upper bound.
  • base can be changed from its default to define another logarithmic scale.

Common mistakes

  • Leaving dtype unset lets NumPy infer the output type from the bounds; specify it when a particular type is required.

Example: Generate logarithmically spaced values

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.

When to use it

Logarithmic visualization ranges

Create tick values spanning several orders of magnitude for plots or axes.

Scale and parameter sweeps

Evaluate an algorithm at geometrically increasing parameter values.

Multiplicative sampling

Construct frequency, size, or tolerance grids where ratios matter more than differences.

Interview questions

QWhat does 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.

QWhat is the role of 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.

QHow do 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.linspace
  • numpy.geomspace

Source: numpy.logspace. Checked 2026-10-15.