【发布时间】:2016-03-03 05:01:08
【问题描述】:
我是torch7的新手,我找不到基于另一个张量获取张量的一些非连续索引的方法。在 numpy 中,我所做的如下:
array = np.zeros(5) # array = [0 0 0 0 0]
indices = np.array([0, 2, 4])
array[indices] = np.array([1, 2, 3]) # array = [1 0 2 0 3]
有没有办法在torch7中做类似的事情?比如:
array = torch.zeros(5) -- array = [0 0 0 0 0]
indices = torch.Tensor({1, 3, 5})
array[indices] = torch.Tensor({1, 2, 3}) -- array = [1 0 2 0 3]
谢谢!
【问题讨论】: