Matrix, Graph, Data Science, Artificial Intelligence, Linear Algebra.
There are no ways to go from B to D using 2 hops. Hence the value is 0. And if you’ve been astute enough to pick it up, the diagonal also happens to tell us the degree of each node, that is, the number of neighbors that each node has: np.diagonal(np.linalg.matrix_power(adj_mat, 2)) # output: