I try creating a matrix using list of list with fixed number of elements. I initialized the matrix with 0 for each cell, then iterate over all the elements and in each cell, I multiply each row and column number like this.
test = [[0] * (10)] * 10
for i in range(10):
for j in range(10):
test[i][j] = i * j
When I print test
, the result is
[[0, 9, 18, 27, 36, 45, 54, 63, 72, 81], [0, 9, 18, 27, 36, 45, 54, 63, 72, 81], [0, 9, 18, 27, 36, 45,54, 63, 72, 81], [0, 9, 18, 27, 36, 45, 54, 63, 72, 81], [0, 9, 18, 27, 36, 45, 54, 63, 72, 81], [0, 9,18, 27, 36, 45, 54, 63, 72, 81], [0, 9, 18, 27, 36, 45, 54, 63, 72, 81], [0, 9, 18, 27, 36, 45, 54, 63,72, 81], [0, 9, 18, 27, 36, 45, 54, 63, 72, 81], [0, 9, 18, 27, 36, 45, 54, 63, 72, 81]]
It looks like only the last i
with i=9
is calculated. What I expect is the result of row and column multiplication.
How to do this in python?