def adjacency_to_transition ( A ): #*****************************************************************************80 # ## adjacency_to_transition() converts an adjacency matrix to a transition matrix. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 07 August 2022 # # Author: # # John Burkardt # # Input: # # integer A(N,N), the adjacency matrix. # # Output: # # real T(N,N): the transition matrix. # import numpy as np n = A.shape[0] # # Get the row sums. # s = np.sum ( A, axis = 1 ) # # Normalize each row so it sums to 1. # T = np.zeros ( [ n, n ] ) for i in range ( 0, n ): if ( s[i] != 0.0 ): T[i,:] = A[i,:] / s[i] else: T[i,i] = 1.0 # # Transpose the matrix. # T = np.transpose ( T ) return T