numpy的坐标操作
import numpy as np
predict = np.random.rand(7, 3)
gt = np.random.randint(0, 3, (7, 1))
# [[0.86111937 0.17885014 0.15346783]
# [0.18914942 0.55776159 0.76759271]
# [0.08425694 0.54494251 0.3043947 ]
# [0.82567279 0.99587862 0.57488206]
# [0.21186169 0.24997568 0.36392427]
# [0.91367358 0.5245865 0.30387125]
# [0.47643958 0.89592537 0.95115335]]
#
#
# [[2]
# [0]
# [2]
# [1]
# [2]
# [0]
# [1]]
有个需求就是比如gt第一行是2就是需要在predict的第一行的2位置值乘以-1, 上面就是需要-0.15346783,其他的以此类推。
实现如下:
import numpy as np
predict = np.random.rand(7, 3)#[7,3]
gt = np.random.randint(0, 3, (7, 1))#[7,1]
predict[[(0,1,2,3,4,5,6), gt.reshape(-1)]] *= -100000
这里为了方便观察,乘以很大值
好记性不如烂键盘---点滴、积累、进步!