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)


Watch video Lect 05: Adjacency Matrix using Networkx || Adjacency Matrix using Python online, duration hours minute second in high quality that is uploaded to the channel Data Science Center 20 May 2022. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 4,227 times and liked it 21 visitors.