【发布时间】:2021-08-28 06:39:56
【问题描述】:
我有两个张量。
tensor_A对应一批8张图片,20类物体,每张图片为256 x 256
tensor_B对应len 20全1或0的8个数组,对应对象类是否存在
tensor_A.shape = ([8, 20, 256, 256])
tensor_B.shape = ([8, 20])
从 tensor_A,我想删除对应于 tensor_B 中 1 的索引
例如如果 tensor_B[0] = [1,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0, 0]
我想做 tensor_A[0, 0, :, :].drop 然后 tensor_A[0, 2, :, :].drop 等等,但都是一步完成
到目前为止,我已经使用以下方法确定了对应于 1 的索引:
for i in range(8):
(tensor_B[i, :] == 0).nonzero())
# code for dropping here
不知道如何继续
【问题讨论】: