Python Practice › NumPy Programs › Program 23

Vector from 1 to 20

EasyNumPy Programs · 23 of 100

Write a NumPy program to create a vector with values 1 to 20.

Advertisement
Output
[ 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20] (20,)

Approach

  1. np.arange(1, 21).

Solution

Python
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.

More numpy programs

← All 100 NumPy Programs

Leave a Comment