Horje
how to convert adjacency list to adjacency matrix Code Example
how to convert adjacency list to adjacency matrix
#Python:
def convert_to_matrix(graph):
    matrix = []
    for i in range(len(graph)): 
        matrix.append([0]*len(graph))
        for j in graph[i]:
            matrix[i][j] = 1
    return matrix
#the lst shows in a form of each index(each inner list) as a form of vertex,
#and each element in the inner list as the vertices that each vertex connected to.
lst = [[1,2,3,5,6],[0,3,6,7],[0,3],[0,1,2,4],[3,5,8],[0,4,8],[0,1],[1],[4,5]]
print(convert_to_matrix(lst)) 




Python

Related
python logger get level Code Example python logger get level Code Example
how to input a string in streamlit Code Example how to input a string in streamlit Code Example
python print datetime Code Example python print datetime Code Example
union dataframe pyspark Code Example union dataframe pyspark Code Example
pyton count number of character in a word Code Example pyton count number of character in a word Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7