Python Practice › NumPy Programs › Program 15
Integers from 1 to 20
Write a NumPy program to create an array of integers from 1 to 20.
Output
[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]
Approach
np.arange(1, 21).
Solution
import numpy as npprint(np.arange(1, 21))Output
[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]
Learn the concept
New to this topic? Read the lesson, then come back.