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 :: how to get value from txtbox in flask 
Python :: pd.read_csv 
Python :: python array colon 
Python :: Write a Python program to sum all the items in a dictionary. 
Python :: numpy expand_dims 
Python :: python loop back to start 
Python :: kill and run process in windows python 
Python :: Download video from a direct URL with Python 
Python :: code fibonacci python 
Python :: get requests python 
Python :: print in python 
Python :: discord bot slash 
Python :: pandas merge df 
Python :: word embedding python 
Python :: seed python 
Python :: filter dict 
Python :: Math Module tan() Function in python 
Python :: compare dates python 
Python :: remove columns from dataframe 
Python :: get last n in list python 
Python :: delete element list python 
Python :: boto3.resource python 
Python :: Python RegEx Findall – re.findall() 
Python :: find max in a dataframe 
Python :: How to send Email verification codes to user in Firebase using Python 
Python :: python tkinter grid 
Python :: numpy remove nan rows 
Python :: sha256 decrypt python 
Python :: connect mysql sql alchemy 
Python :: Handling categorical feature 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =