I\'m using a list of lists to store a matrix in python. I tried to initialise a 2x3 Zero matrix as follows.
mat=[[0]*2]*3
However, when I chang
Use a list comprehension:
>>> mat = [[0]*2 for x in xrange(3)] >>> mat[0][0] = 1 >>> mat [[1, 0], [0, 0], [0, 0]]
Or, as a function:
def matrix(rows, cols): return [[0]*cols for x in xrange(rows)]