pythonfunctionnumpyincludelinspace

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?


Solution

  • 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 -