Python arange() Function

The arange() function in numpy is same as range() function in Python. The arange() function is used in the following format:

arange(start, stop, stepsize)

This creates an array with a group of elements from 'start' to one element prior to 'stop' in steps of 'stepsize'. If the 'stepsize' is omitted, then it is taken as 1. If the 'start' is omitted, then it is taken as 0. For example,

arange(10)

will produce an array with elements 0 to 9

arange(10, 1, -1)

Since the stepsize is -1, it represents the elements in descending order from 10 to 2, as:

[10 9 8 7 6 5 4 3 2].

arange() function examples:

CopiedCopy Code

from numpy import * 
a = arange(2, 11, 2)
print(a)
                            

CopiedCopy Code

from numpy import * 
a = arange(15, 3, 2)
print(a)
							
							

CopiedCopy Code

from numpy import * 
a = arange(8, 1, -1)
print(a)
                            

CopiedCopy Code

from numpy import * 
a = arange(15, 3, -2)
print(a)