I am writing a code to multiply two matrices, using the equation c[i][j] = (0<k<n)Sigma(a[i][k]*b[k][j]) But in first iteration, my final matrix goes from
[
[0,0,0]
[0,0,0]
]
to
[
[2,0,0]
[2,0,0]
]
That is an error because according to my code, only the [0][0]th element should be getting changed to 2, not [1][0]th element too. This is a bit hard to explain over text. Here is my code snippet which doesn't work as meant to
scaledMatrix = [[0]*3]*n
for i in range(n):
for j in range(3):
sum_of_elements = 0
for k in range(n):
sum_of_elements += coordinateMatrix[i][k]*otherMatrix[k][j]
scaledMatrix[i][j] = sum_of_elements