Python Practice › NumPy Programs › Program 19

3 × 3 matrix

EasyNumPy Programs · 19 of 100

Write a NumPy program to create a 3 × 3 matrix.

Advertisement
Output
[[1 2 3]
 [4 5 6]
 [7 8 9]]

Approach

  1. arange(9).reshape(3, 3).

Solution

Python
import numpy as npprint(np.arange(1, 10).reshape(3, 3))
Output
[[1 2 3]
 [4 5 6]
 [7 8 9]]
Advertisement

Learn the concept

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

More numpy programs

← All 100 NumPy Programs