When I have a=1 and b=2, I can write a,b=b,a so that a and b are interchanged with each other.
a=1
b=2
a,b=b,a
a
b
I use
if you need to swap the mth and the nth rows, you could you the following code:
temp = a[m,:].copy() a[m,:] = a[n,:] a[n,:] = temp
you can extrapolate the same concept for swapping the columns by changing the indices.