Python Practice › NumPy Programs › Program 23
Vector from 1 to 20
Write a NumPy program to create a vector with values 1 to 20.
Output
[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] (20,)
Approach
np.arange(1, 21).
Solution
import numpy as npv = np.arange(1, 21)print(v, v.shape)Output
[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] (20,)
Learn the concept
New to this topic? Read the lesson, then come back.