Python Practice › NumPy Programs › Program 15

Integers from 1 to 20

EasyNumPy Programs · 15 of 100

Write a NumPy program to create an array of integers from 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]

Approach

  1. np.arange(1, 21).

Solution

Python
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]
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More numpy programs

← All 100 NumPy Programs