Skip to content
LearnPY
NumPyfunction reference

np.arange

Create evenly spaced values within a half-open interval.

Signature

np.arange(start, stop=None, step=1, dtype=None)

What it does

np.arange behaves like Python's range but returns an array. It starts at start, stops before stop, and advances by step. Floating-point steps can accumulate representation error.

Parameters

startnumber
The first value, or the stop value when stop is omitted.
stopnumber, optionaloptional
The end of the interval, excluded from the result.
stepnumber, optionaloptional
The distance between consecutive values.

Returns

ndarray

Example

pythonnp.arange example
import numpy as np

print(np.arange(0, 10, 2))

Output

[0 2 4 6 8]

Watch out for

  • The stop value is excluded, matching range semantics.
  • Prefer linspace when you need a specific number of points and exact endpoints.