Lab 2.2

Block Matrices and Graphs

Focus
join blocks → multiply → count walks
Notebook
Ch2-2 Block Matrices & Graphs.ipynb

Lab goal

Explain how np.block joins compatible rectangles and why one entry of a squared adjacency matrix counts length-two walks.

Lecture-note concepts
  • Block matrices
  • Block multiplication
  • Adjacency matrix
  • Walk counts

Code extensionThe full notebook continues to Schur complements, block inverses, longer walks, and bipartite reordering.

Key ideas

Terms you will use

Compatible blocksX = [[A, B], [C, D]]

Blocks in one block row need the same height; blocks in one block column need the same width.

Block multiplicationtop-left = A E + B G

The usual row-by-column rule still applies when each entry is itself a compatible matrix.

Adjacency power(adj²)ᵢⱼ = # two-step walks

Entry (i,j) of G² counts the length-two walks from vertex i to vertex j.

Lab 2.2 · Guided example

See blocks and graph walks with small matrices

This trace keeps two ideas from the notebook—block arithmetic and adjacency powers—and removes the larger inverse and 8-vertex examples.

Select a line to see its action, array shape, and concrete operation.

Simplified fromCh2-2 Block Matrices & Graphs.ipynbThe values and graph are intentionally smaller than the full notebook examples.

Line 1: import numpy as np
L01 / 20Join four compatible blocks
Predict

The four definitions become one 3×3 matrix.

Before

Two ideas, one rule

Matrix multiplication combines compatible rows and columns, whether we view them as blocks or graph connections.

row × column → one output entry
After
?

Reveal to compare.

X.shapenot stored A complete square matrix.

Continue in Python

Run the complete notebook in Colab

Run the original code and change the inputs.