不多废话,例子如下:
import numpy as np
arr = np.arange(20)
b = arr.reshape(4,5)
b[(0,1),:] = b[(1,0),:]#交换两行
b[:,(0,1)] = b[:,(1,0)]#交换两列
print(b)
结果:
[[ 6 5 7 8 9]
[ 1 0 2 3 4]
[11 10 12 13 14]
[16 15 17 18 19]]
不多废话,例子如下:
import numpy as np
arr = np.arange(20)
b = arr.reshape(4,5)
b[(0,1),:] = b[(1,0),:]#交换两行
b[:,(0,1)] = b[:,(1,0)]#交换两列
print(b)
结果:
[[ 6 5 7 8 9]
[ 1 0 2 3 4]
[11 10 12 13 14]
[16 15 17 18 19]]