Skip to content
Advertisement

Numpy linspace function stop value

I giving start and stop values as parameters to the linspace function Stop value is normally does not include in the array. Because of this we always write [stop+1] in order to make include the stop value. But in linspace, if i write

np.linspace(0, 20, 5)

the output is:

[0, 5, 10, 15, 20]

Why linspace function output includes the stop value when arange function does not?

Advertisement

Answer

from Numpy linspace documnetation Parameter

endpoint : bool, optional If True, stop is the last sample. Otherwise, it is not included. Default is True.

as explained nicely here the 2 functions are similar with slightly different approaches –

  • linspace’s goal is to give us a list of values equally spaced between the start point and endpoint, the only required parameter (except for the start/end) is how many items do we want. Therefore the end considers a legitimate item in that list.

  • arrange’s goal is to give a list of steps according to the stepsize parameter we gave it. we’re handling the steps so I guess the end doesn’t concern us this is my two cents for this issue…

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement