New paste Repaste Download
import numpy as np
def calculate_pagerank(graph, damping_factor=0.85, max_iterations=100, tolerance=1e-6):
    num_nodes = len(graph)
    pr = np.ones(num_nodes) / num_nodes
    for _ in range(max_iterations):
        pr_new = (1 - damping_factor) / num_nodes + damping_factor * np.dot(graph, pr)
        diff = np.linalg.norm(pr_new - pr)
        if diff < tolerance:
            return pr_new
        pr = pr_new
    return pr_new
# Example usage:
graph = np.array([
    [0, 1, 0],
    [1, 0, 1],
    [0, 0, 1]
])
page_rank = calculate_pagerank(graph)
print(page_rank)
import numpy as np
# Create a simple graph with the given pages and links
A = np.array([[0, 0, 0],
              [0, 0, 0],
              [0, 0, 0]])
B = np.array([[0, 0, 0],
              [0, 0, 0],
              [0, 0, 0]])
C = np.array([[0, 1, 0],
              [1, 0, 1],
              [0, 0, 0]])
graph = np.maximum(A, np.maximum(B, C))
print(graph)
Filename: None. Size: 994b. View raw, , hex, or download this file.

This paste expires on 2024-05-23 04:31:59.112529. Pasted through web.