Skip to content

Instantly share code, notes, and snippets.

@evanthebouncy
Created August 6, 2020 13:45
Show Gist options
  • Save evanthebouncy/8728aebe56b6a8bd4c1a73c04937ce51 to your computer and use it in GitHub Desktop.
Save evanthebouncy/8728aebe56b6a8bd4c1a73c04937ce51 to your computer and use it in GitHub Desktop.
def normalise(mat, axis):
if axis == 0:
row_sums = mat.sum(axis=1)
new_matrix = mat / row_sums[:, np.newaxis]
return new_matrix
if axis == 1:
col_sums = mat.sum(axis=0)
new_matrix = mat / col_sums[np.newaxis, :]
return new_matrix
L0 = normalise(sat, 0)
start_acc = comm_acc(S0, L0)
S, L = S0, L0
for i in range(100):
S = normalise(L, 1)
L = normalise(S, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment