0 votes
in Python by
Explain numpy.arrange() in Python

1 Answer

0 votes
by

Python numpy.arrange()

The arrange() function of Python numpy class returns an array with equally spaced elements as per the interval where the interval mentioned is half opened, i.e. [Start, Stop).

Syntax

numpy.arange([start, ]stop, [step, ]dtype=None)

Parameter

start :It is an optional parameter which represents the start of the interval range. By default,the value of start is 0.

stop  :This parameter represents the end of the interval range.

step  :It is an optional parameter representing the step size of the interval. By default, step size = 1.

dtype :This parameter represents the type of output array.

Return

This function returns an array of evenly spaced values.

Example 1

# Python Programming explaining
# numpy.arange()function
importnumpy as np
print("Arrange method:\n", np.arange(4).reshape(2, 2), "\n")
print("", np.arange(4, 10), "\n")
print("", np.arange(4, 20, 3), "\n")

Output

Arrange method:

[[0 1]
[2 3]]
[4 5 6 7 8 9]
[ 4  7 10 13 16 19]
...