Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

import numpy as np

import matplotlib.pyplot as plt


import networkx as nx

Z = [
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 0],
[1, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 1, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0]
]

G = nx.from_numpy_matrix(np.array(Z), create_using=nx.DiGraph())
[
G.add_node(k) for k in [1,2,3,4]]
G.add_edge(2,1)
G.add_edge(3,1)
G.add_edge(4,1)
ppr1 = nx.pagerank(G,personalization={1:1, 2:1, 3:1, 4:1})
print("The PageRank is:")
print(ppr1)
pos = nx.circular_layout(G)
nx.draw_circular(G)
labels = {i : i + 1 for i in G.nodes()}
nx.draw_networkx_labels(G, pos, labels, font_size=18)
plt.show()

You might also like