I'm trying to change the value of a certain element in a 2D array.
the 2D array is a num1 by num2 matrix with every element as 0. I'm trying to change the Rth
row Cth
column of the matrix to 1
matrix = []
def make_matrix(num1, num2):
row = []
for i in range(num1):
row.append(0)
for i in range(num2):
matrix.append(row)
def change_to_one(R, C):
matrix[R-1][C-1] = 1
make_matrix(3, 2)
change_to_one(2, 1)
print(matrix)
it prints [[1, 0, 0], [1, 0, 0]]
instead of [[0, 0, 0], [1, 0, 0]]