How to Reverse a Torch Tensor
How to Reverse a Torch Tensor
peak
<SCODE>tensor = torch.rand(10) # your tensor
# create inverted indices
idx = [i for i in range(tensor.size(0)-1, -1, -1)]
idx = torch.LongTensor(idx)
inverted_tensor = tensor.index_select(0, idx)
<ECODE>
fmassa
Hi, it looks like this can’t work on torch.autograd.variable.Variable. Is there any way to reverse a specific dimension in a Variable? Thanks!
qianguih
apaszke
If your use case is to reverse sequences to use in Bidirectional RNNs, I just create a clone and flip using numpy. <SCODE>rNpArr = np.flip(fTensor.numpy(),0).copy()   #Reverse of copy of numpy array of given tensor
rTensor = torch.from_numpy(rNpArr)          
<ECODE>
DiffEverything
Can you try something like:
Sunil_Sharma
aRI0U
chorus12