Python Practice › NumPy Programs › Program 28

2 × 2 matrix

EasyNumPy Programs · 28 of 100

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

Advertisement
Output
[[1 2]
 [3 4]]

Approach

  1. From a nested list.

Solution

Python
import numpy as npprint(np.array([[1, 2], [3, 4]]))
Output
[[1 2]
 [3 4]]

Learn the concept

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

More numpy programs

← All 100 NumPy Programs

Leave a Comment