Closed JinglUO703 closed 4 years ago
res[indices.cpu().numpy()] = updates
that will work
@JinglUO703
The fast way is
res[indices.long()] = updates
(Optional way) Also, since indices
here are not dynamic index, np.ndarray might be better in compatibility. It can be fixed by following codes:
# indices = torch.from_numpy(np.reshape(
# np.reshape(np.arange(0, batch_size) * 9, [-1, 1]) + col_inds,
# newshape=(-1,))).to(device)
indices = np.reshape(np.reshape(np.arange(0, batch_size) * 9, [-1, 1]) + col_inds, newshape=(-1, ))
We will fix this soon, and the solution proposed by @fuzuoyi is also feasible.
res[indices.cpu().numpy()] = updates
那可行
res[indices.cpu().numpy()] = updates
那可行
Thanks,at first I thought it was numpy version
@ JinglUO703
- 快速的方法是
res [indices.long()] =更新
- (可选方式)而且,由于
indices
这里不是动态索引,因此np.ndarray的兼容性可能更好。可以通过以下代码进行修复:#索引= torch.from_numpy(np.reshape( # np.reshape(np.arange(0,batch_size)* 9,[-1,1])+ col_inds, # newshape =(-1,)))。to(设备) #为了更好的兼容性,由于索引为torch.tensor,因此必须为long dtype。 #对于固定索引,np.ndarray可能更好。 指数 = np.reshape(np.reshape(np.arange( 0,的batch_size) * 9,[ - 1, 1 ]) + col_inds, newshape =( - 1))
我们将尽快修复此问题,@ fuzuoyi提出的解决方案也是可行的。
3Q,I have solved this problem through @fuzuoyi method.