我编写了以下代码来翻转2d numpy数组行中的两个值。然而,我想知道是否有更好的方法来做到这一点。提前谢谢
def mtn(offg):
for row in range(offg.shape[0]):
point1 = random.randint(0, 139)
point2 = random.randint(0, 139)
temp = offg[row, point1]
offg[row, point1] = offg[row, point2]
offg[row, point2] = temp
return offg
Tags:
如果每行中的点相同,则可以使用如下代码
您可以使用高级索引:
相关问题 更多 >
编程相关推荐