The shortest and most elegant way (from my perspective) is:

import numpy as np

start = 0
step = 1.25
num = 9

result = start + np.arange(0, num) * step

returns

[  0.     1.25   2.5    3.75   5.     6.25   7.5    8.75  10.  ]
Answer from Markus Dutschke on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-linspace
NumPy linspace() Method | Create Evenly Spaced Array - GeeksforGeeks
February 14, 2026 - DSA Python · Data Science · NumPy · Pandas · Practice · Django · Flask · Last Updated : 14 Feb, 2026 · The numpy.linspace() function is used to generate an array of evenly spaced values between two specified numbers.
🌐
DataCamp
datacamp.com › home › tutorials › python › how to use the numpy linspace() function
How to Use the NumPy linspace() Function | DataCamp
April 5, 2024 - If False, the stop value is not included in the sequence generated by linspace(). This means that the function will create evenly spaced samples within the range from start to just before stop, effectively excluding the stop value itself from the sequence. This can be useful when you need a range that approaches but does not reach the endpoint, allowing for more flexible control over the range of values generated. retstep (optional): If True, returns (samples, step), where step is the spacing between samples.
🌐
Real Python
realpython.com › np-linspace-numpy
np.linspace(): Create Evenly or Non-Evenly Spaced Arrays – Real Python
July 3, 2026 - In this tutorial, you'll learn how to use NumPy's np.linspace() effectively to create an evenly or non-evenly spaced range of numbers. You'll explore several practical examples of the function's many uses in numerical applications.
🌐
Codecademy
codecademy.com › docs › python:numpy › built-in functions › .linspace()
Python:NumPy | Built-in Functions | .linspace() | Codecademy
May 26, 2025 - Returns a numpy ndarray of evenly spaced samples. If retstep is True, it also returns the step size between samples. This example shows how to create a simple array of evenly spaced numbers using the .linspace() function:
🌐
NumPy
numpy.org › doc › stable › user › how-to-partition.html
How to create arrays with regularly-spaced values — NumPy v2.5 Manual
Use numpy.linspace if you want the endpoint to be included in the result, or if you are using a non-integer step size. numpy.linspace can include the endpoint and determines step size from the num argument, which specifies the number of elements in the returned array.
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: arange() and linspace() to generate evenly spaced values | note.nkmk.me
February 2, 2024 - In the case of np.linspace(), simply swapping the first argument (start) with the second (stop) can easily reverse the order if endpoint=True.
🌐
Python Guides
pythonguides.com › python-numpy-linspace
NumPy's Linspace Function In Python
May 7, 2025 - np.linspace takes a count, not a step, and always includes the stop. The spacing formula, retstep, dtype truncation and why arange is risky with floats.
Find elsewhere
Top answer
1 of 2
3

Your intuition seems to be that if endpoint=False is specified, then the last element of the returned array should be 1 less than the stop value.

Suppose we implement things that way. What does the following linspace call return?

numpy.linspace(0, 0.5, 5, endpoint=False)

Is it going to end at -0.5, counting down? That wouldn't make much sense.


numpy.linspace always divides the interval from start to stop into equally-sized chunks, and it always returns an array of length num. The difference between endpoint=True and endpoint=False is that with endpoint=False, it makes one extra chunk to compensate for leaving out the right endpoint. The step from 16 to 18 is the same size as the step from 18 to the omitted 20.

2 of 2
0

It would be helpful to look at the source here. This will allow you to walk through what the function is doing, which will give you a better understanding of the output of linspace.


Two parameters are used to calculate the step size: div and delta. However, the difference between endpoint=True, and endpoint=False, is that div is equal to num-1 if endpoint=True, and num if endpoint=False.

div = (num - 1) if endpoint else num

Here are the other relevent pieces of the source (very slimmed down):

delta = stop - start

y = _nx.arange(0, num, dtype=dt)

# ...

if num > 1:
    step = delta / div

# ...

y = y * step

# ...

y += start

If we walk through each of these the outputs make a lot more sense.

endpoint=True:

div = num - 1                     # 4
y = _nx.arange(0, num, dtype=dt)  # [0, 1, 2, 3, 4]
delta = 20 - 10                   # 10
step = delta / div                # 2.5
y = y * step                      # [0.0, 2.5, 5.0, 7.5, 10.0]
y += start                        # [10.0, 12.5, 15.0, 17.5, 20.0]

endpoint=False:

div = num                         # 5
y = _nx.arange(0, num, dtype=dt)  # [0, 1, 2, 3, 4]
delta = 20 - 10                   # 10
step = delta / div                # 2
y = y * step                      # [0.0, 2.0, 4.0, 6.0, 8.0]
y += start                        # [10.0, 12.0, 14.0, 16., 18.0]
🌐
Fritz ai
fritz.ai › home › blog › exploring numpy’s linspace() function
Exploring NumPy’s linspace() function - Fritz ai
September 15, 2023 - The np.linspace() function has the word space in its name; however, it doesn’t accept an explicit argument defining the space between every 2 numbers. The space, or more meaningful step, is calculated indirectly using the num argument.
🌐
AskPython
askpython.com › python-modules › numpy › numpy-linspace-python
NumPy linspace(): Create Arrays Fast - AskPython
January 24, 2026 - The np.linspace function prioritizes endpoint precision. You specify exactly where to start and stop, plus how many values you need. NumPy calculates the step size.
🌐
Squash
squash.io › how-to-use-python-linspace-function
How to Use Python's Linspace Function - Squash.io
August 30, 2024 - The endpoint value of 1 is not included in the sequence. The concept of step in the numpy linspace function refers to the difference between consecutive values in the generated sequence.
🌐
Kodeclik
kodeclik.com › numpy-linspace-python
Numpy Linspace numpy.linspace() in Python
August 22, 2024 - One additional feature of linspace is, because we only specify the number of values we need and not the step size, we can ask it to return the stepsize for us (by specifying retstep=True, i.e., retstep refers to “return step”).
🌐
datagy
datagy.io › home › numpy › numpy linspace: creating evenly spaced arrays with np.linspace
NumPy linspace: Creating Evenly Spaced Arrays with np.linspace • datagy
December 30, 2022 - The benefit of the linspace() function becomes clear here: we don’t need to define and understand the step size before creating our array. By default, NumPy will include the stop value specified in the function. This behavior is different from many other Python functions, including the Python range() function.
🌐
LabEx
labex.io › tutorials › generating-evenly-spaced-numbers-with-numpy-86473
NumPy Linspace Tutorial | Evenly Spaced Numbers | LabEx
In this tutorial, we will cover the usage of the numpy.linspace() function in the NumPy library. This function is used to generate evenly spaced numbers over a specified interval.
🌐
Squash
squash.io › python-linspace-a-handy-tool-for-generating-equidistant-numeric-sequences
How to Generate Equidistant Numeric Sequences with Python
In addition to generating increasing sequences, the linspace function in Python also allows you to generate sequences in reverse order by using a negative step parameter.
🌐
Medium
heartbeat.comet.ml › exploring-numpys-linspace-function-bb3378f8dcd8
Exploring NumPy’s linspace() function | by Ahmed Gad | Heartbeat
September 28, 2021 - The np.linspace() function has the word space in its name; however, it doesn’t accept an explicit argument defining the space between every 2 numbers. The space, or more meaningful step, is calculated indirectly using the num argument.