Basically I have a 10000x10000 matrix named M and there are 1s and 0s in every column. I'm trying to count the number of 1s in every column and then divide every element in that column with this number.
This is what I have tried:
outbound_links = M[M == 1].count()
mat = [[1] * 10000] * 10000
n = 10000
#len(mat)
# for each column
for col_index in range(0, n):
# count the number of 1s
for row_index in range(0, n):
if M[row_index][col_index] == 1:
mat[row_index][col_index] = 1 / outbound_links[col_index]
else:
mat[row_index][col_index] = 0
print(mat)
But the code is unable to run because it seems too big a matrix. I was wondering what other alternatives I could use?