Python Practice › NumPy Programs › Program 14
Array of three ones
Write a NumPy program to create an array of 3 ones.
Output
[1 1 1] [1. 1. 1.]
Approach
np.ones(3, dtype=int).
Solution
import numpy as npprint(np.ones(3, dtype=int), np.ones(3))Output
[1 1 1] [1. 1. 1.]
Learn the concept
New to this topic? Read the lesson, then come back.