Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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)) 
Comment

PREVIOUS NEXT
Code Example
Python :: check if file is txt python 
Python :: What is role of ALLOWED_HOSTs in Django 
Python :: python slice notation 
Python :: django deployment 
Python :: string to tuple python 
Python :: how to count things in a list python 
Python :: in python how to use exp 
Python :: seaborn pink green color palette python 
Python :: python global variable across files 
Python :: python package for misspelled words 
Python :: pass a list to a function in python 
Python :: Custom x, y-ticks using plt 
Python :: python argparse optional required 
Python :: python download complete web page 
Python :: Fast api importing optional 
Python :: heroku django procfile 
Python :: matplotlib set integer ticks 
Python :: how to put song in pygame 
Python :: how to get prime numbers in a list in python using list comprehension 
Python :: get last 3 in list python 
Python :: jupyter dark theme vampire 
Python :: how to write a code for anagram in python 
Python :: input in python 
Python :: python youtube downloader 
Python :: get current domain name django 
Python :: Python from...import statement 
Python :: in dataframe particular column to string 
Python :: python get current date and time 
Python :: hostname python 
Python :: target ordinary encodiing) 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =