Matrix, Graph, Data Science, Artificial Intelligence, Linear Algebra.
by taking k hops on the graph. Let’s see the example of k = 2: np.linalg.matrix_power(adj_mat, 2) # output: array([[2., 1., 1., 1.], [1., 3., 1., 0.], [1., 1., 2., 1.], [1., 0., 1., 1.]]) As we can see, there are two ways to go from A and back to A (value = 2), by going A -> B -> A and A -> C -> A.