3.3

点击查看代码
import numpy as np
import pandas as pd
import sympy as sp
sp.init_printing(use_unicode=True)
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['Times New Roman + SimSun + WFM Sans SC']
plt.rcParams['mathtext.fontset']='cm'
# Times New Roman + SimSun + WFM Sans SC
# simsum宋体, times new roman -*, simhei黑体, kaiti楷体,
# dengxian等线, fangsong仿宋, Microsoft Yahei微软雅黑
plt.rcParams['axes.unicode_minus']=False
plt.rcParams['figure.dpi'] = 200
# plt.rcParams['figure.figsize'] = [4, 3]
# plt.rcParams['font.size'] = 12
plt.rcParams['xtick.direction'] = 'in'
plt.rcParams['ytick.direction'] = 'in'
from scipy.sparse.linalg import eigs
L = np.array([[0, 1, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1],
             [1, 1, 0, 1, 0, 0], [0, 0, 0, 0, 1, 1],
             [0, 0, 1, 0, 0, 1], [0, 0, 1, 0, 0, 0]])
r = np.sum(L, axis=1, keepdims=True)
P = L/r
d = 0.85
Ptilde = (1-d)/len(P)*np.ones_like(P) + d*P
val, vec = eigs(Ptilde.T, 1)
V = vec.flatten()
V = V.real
V /= sum(V)
print(V)
fig, ax = plt.subplots()
ax.bar(range(1, len(V)+1), V, width=0.6)
ax.set_xlabel('Page')
ax.set_ylabel('Rank')
fig.show()

posted @ 2024-10-28 12:57  2023310143015  阅读(7)  评论(0)    收藏  举报