If i have the matrix:
[[1,1,1],[2,3,4],[4,5,6],[7,1,2]]
I want to swap rows 1 and 2 so that it returns:
[[1,1,1],[4,5,6],[2,3,4],[7,1,2]]
If i have the matrix:
[[1,1,1],[2,3,4],[4,5,6],[7,1,2]]
I want to swap rows 1 and 2 so that it returns:
[[1,1,1],[4,5,6],[2,3,4],[7,1,2]]
You can do this the same way you do any other swap in python:
i.e. a, b = b, a
-- or in your case:
>>> matrix = [[1,1,1],[2,3,4],[4,5,6],[7,1,2]]
>>> matrix[1], matrix[2] = matrix[2], matrix[1]
>>> matrix
[[1, 1, 1], [4, 5, 6], [2, 3, 4], [7, 1, 2]]