We will create a matrix from two smaller matrices as follows:
A = np.eye(2) print("A", A)
The identity matrix looks like the following:
A [[ 1. 0.] [ 0. 1.]]
A
and multiply it by 2:B = 2 * A print("B", B)
The second matrix is as follows:
B [[ 2. 0.] [ 0. 2.]]
mat()
function—use matrices instead of numbers:print("Compound matrix ", np.bmat("A B; A B"))
The compound matrix is shown as follows:
Compound matrix [[ 1. 0. 2. 0.] [ 0. 1. 0. 2.] [ 1. 0. 2. 0.] [ 0. 1. 0. 2.]]
We created a block matrix from two smaller matrices with the bmat()
function. We gave the function a string containing the names of matrices instead of numbers (see bmatcreation.py
):
from __future__ import print_function import numpy as np A = np.eye(2) print("A", A) B = 2 * A print("B", B) print("Compound matrix ", np.bmat("A B; A B"))