Header Ads

Header ADS

How to Convert a matrix of a graph into an adjacent matrix in python?



#given matrix
matrix = [[False,True,False],
 [True,False,False],
 [False,False,False]]

#a funtion which converts the matrix into adjacency_matrix
def matrixcon(matrix):
    List = {}
    for i in range(len(matrix)):
        List[i]=[]
        for j in range(len(matrix[i])):
            if matrix[i][j]==True:
                List[i]+=[j]
    return List



Con_graph=matrixcon(matrix)
print(dfs_recursive(Con_graph, 2))

No comments

Theme images by enot-poloskun. Powered by Blogger.