While I initialize a square matrix with all elements as 0 and try to manipulate one of the elements, a weird "bug" happens:
Here is the sample code for a 3 * 3 matrix:
row = [0] * 3
matrix = []
for i in range(3):
matrix.append(row)
matrix[0][1]=2
I try to change one element say matrix[0][1] to 2, all elements on the column 1 change to 2
[0,2,0]
[0,2,0]
[0,2,0]
Can anyone please help explain what's going on here? I only try to change one element only.