Python Practice › NumPy Programs › Program 14

Array of three ones

EasyNumPy Programs · 14 of 100

Write a NumPy program to create an array of 3 ones.

Advertisement
Output
[1 1 1] [1. 1. 1.]

Approach

  1. np.ones(3, dtype=int).

Solution

Python
import numpy as npprint(np.ones(3, dtype=int), np.ones(3))
Output
[1 1 1] [1. 1. 1.]
Advertisement

Learn the concept

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

More numpy programs

← All 100 NumPy Programs