Skip to content
DeepForgeby svx
All problems
EasyGraph Algorithmsgraph-096

HITS Normalization

Problem

Normalize hub and authority score vectors to unit L2 length.

Divide each vector by its Euclidean norm; leave an all-zero vector unchanged as zeros. Return [hubs, authorities].

Hint

L2 normalization keeps the direction of the score vector but makes its length one.

Test cases

case 1
in: [[3,0,0],[0,1,1]]
expected: [[1,0,0],[0,0.7071067811865475,0.7071067811865475]]
case 2
in: [[0,0],[0,0]]
expected: [[0,0],[0,0]]
case 3
in: [[1,1],[2,2]]
expected: [[0.7071067811865475,0.7071067811865475],[0.7071067811865475,0.7071067811865475]]
case 4
in: [[0,3,4],[0,0,0]]
expected: [[0,0.6,0.8],[0,0,0]]
Starter codePython
import math
def normalize_hits(hubs, auth):
    # Your code here
    pass

4 test cases · run your code against them in the editor