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

Veröffentlicht am: 20 Mai 2022
auf dem Kanal: 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)


Auf dieser Seite können Sie das Online-Video Lect 05: Adjacency Matrix using Networkx || Adjacency Matrix using Python mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Data Science Center 20 Mai 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 4,227 Mal angesehen und es wurde von 21 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!