Swapping Columns with NumPy arrays

前端 未结 5 1342
余生分开走
余生分开走 2020-12-14 11:54

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.

I use

5条回答
  •  时光说笑
    2020-12-14 12:42

    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.

提交回复
热议问题