Python Practice › NumPy Programs › Program 26
3 × 4 matrix
Write a NumPy program to create a 3 × 4 matrix.
Output
[[ 1 2 3 4] [ 5 6 7 8] [ 9 10 11 12]]
Approach
- Reshape 12 numbers.
Solution
import numpy as npprint(np.arange(1, 13).reshape(3, 4))Output
[[ 1 2 3 4] [ 5 6 7 8] [ 9 10 11 12]]
Learn the concept
New to this topic? Read the lesson, then come back.