Python Practice › NumPy Programs › Program 17

Odd integers from 1 to 20

EasyNumPy Programs · 17 of 100

Write a NumPy program to create an array of odd integers from 1 to 20.

Advertisement
Output
[ 1  3  5  7  9 11 13 15 17 19]

Approach

  1. np.arange(1, 21, 2).

Solution

Python
import numpy as npprint(np.arange(1, 21, 2))
Output
[ 1  3  5  7  9 11 13 15 17 19]

Learn the concept

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

More numpy programs

← All 100 NumPy Programs

Leave a Comment