Lect 05: Adjacency Matrix using Networkx || Adjacency Matrix using Python

Published: 20 May 2022
on channel: Data Science Center
4,227
21

Adjacency Matrix is a 2D array of size V x V where V is the number of vertices in a graph.
Let the 2D array slot adj[i][j] = 1 indicates that there is an edge from vertex i to vertex j.
Adjacency matrix for undirected graph is always symmetric. Adjacency Matrix is also used to represent weighted graphs. If adj[i][j] = w, then there is an edge from vertex i to vertex j with weight w.
Python code is as:
========================================
V = ['A', 'B', 'C', 'D']
E = [('A', 'B', 12), ('B', 'C', 12), ('C', 'D',11), ('D', 'A', 3), ('B', 'D', 10), ('A', 'C', 9)]

pos = {'A':[1,1], 'B':[3, 1], 'C':[3, 3], 'D':[1,3]}

#Directed Graph
G = nx.DiGraph()

G.add_nodes_from(V)

G.add_weighted_edges_from(E)

G.nodes

G.edges

weight = nx.get_edge_attributes(G, 'weight')

nx.draw_networkx(G, with_labels=True, pos=pos, node_size= 1500, node_color='r', edge_color='g', arrowsize=33, font_size=16)
nx.draw_networkx_edge_labels(G, pos, edge_labels=weight, font_size=16)

nx.to_pandas_edgelist(G)
nx.to_pandas_adjacency(G)


On this page of the site you can watch the video online Lect 05: Adjacency Matrix using Networkx || Adjacency Matrix using Python with a duration of hours minute second in good quality, which was uploaded by the user Data Science Center 20 May 2022, share the link with friends and acquaintances, this video has already been watched 4,227 times on youtube and it was liked by 21 viewers. Enjoy your viewing!