Python Practice › NumPy Programs › Program 26

3 × 4 matrix

EasyNumPy Programs · 26 of 100

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

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

Approach

  1. Reshape 12 numbers.

Solution

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

Learn the concept

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

More numpy programs

← All 100 NumPy Programs