Whay is Arrange?

Sometimes, you want to create values that are evenly spaced within a defined interval. For instance, you want to create values from 1 to 10; you can use numpy.arange() function

Syntax:

numpy.arange(start, stop,step) 
  • Start: Start of interval
  • Stop: End of interval
  • Step: Spacing between values. Default step is 1

Example:

import numpy np
np.arange(1, 11)			

Output:

array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10])			

Example:

If you want to change the step, you can add a third number in the parenthesis. It will change the step.

import numpy np
np.arange(1, 14, 4)			

Output:

array([ 1,  5,  9, 13])			

 

YOU MIGHT LIKE: