Arrays - arange()
NumPy - The Basics
1 min read
This section is 1 min read, full guide is 14 min read
Published Sep 22 2025
11
Show sections list
0
Log in to enable the "Like" button
0
Guide comments
0
Log in to enable the "Save" button
Respond to this guide
Guide Sections
Guide Comments
NumPyPython
What np.arange()
Does
numpy.arange()
creates an array with evenly spaced values within a specified range.- It’s similar to Python’s built-in
range()
, but returns a NumPy array instead of a list, and supports non-integer steps (like 0.5).
Function Signature
numpy.arange([start, ]stop, [step], dtype=None)
Copy to Clipboard
- start → (optional) starting value (default = 0).
- stop → end value (excluded).
- step → spacing between values (default = 1).
- dtype → data type of the output array (optional).
Examples
import numpy as np
# Default start=0, step=1
np.arange(5)
# → [0 1 2 3 4]
# Custom start and stop
np.arange(2, 7)
# → [2 3 4 5 6]
# With step
np.arange(1, 10, 2)
# → [1 3 5 7 9]
# With float step
np.arange(0, 1, 0.2)
# → [0. 0.2 0.4 0.6 0.8]
Copy to Clipboard
Toggle show comments
np.arange()
is a quick way to create number sequences as NumPy arrays, flexible with integer or float steps.