numpy.linspace()

It is similar to the arrange function. However, it doesn?t allow us to specify the step size in the syntax.

Instead of that, it only returns evenly separated values over a specified period. The system implicitly calculates the step size.

Syntax

snippet
numpy.linspace(start, stop, num, endpoint, retstep, dtype)

Parameters

It accepts the following parameters.

  1. start: It represents the starting value of the interval.
  2. stop:It represents the stopping value of the interval.
  3. num: The amount of evenly spaced samples over the interval to be generated. The default is 50.
  4. endpoint: Its true value indicates that the stopping value is included in the interval.
  5. rettstep: This has to be a boolean value. Represents the steps and samples between the consecutive numbers.
  6. dtype: It represents the data type of the array items.

Return

An array within the specified range is returned.

Example 1

snippet
import numpy as np
arr = np.linspace(10, 20, 5)
print("The array over the given range is ",arr)

Output:

Output
The array over the given range is [10. 12.5 15. 17.5 20.]

Example 2

snippet
import numpy as np
arr = np.linspace(10, 20, 5, endpoint = False)
print("The array over the given range is ",arr)

Output:

Output
The array over the given range is [10. 12. 14. 16. 18.]
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +