Python Practice › NumPy Programs › Program 17
Odd integers from 1 to 20
Write a NumPy program to create an array of odd integers from 1 to 20.
Output
[ 1 3 5 7 9 11 13 15 17 19]
Approach
np.arange(1, 21, 2).
Solution
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.