How to change (assign) new value in FloatTensor, Pytorch?
I am changing/assigning the value on the array(torch.cuda.floatTensor). I tried some way but it does not work. Please help me!

#1

#dis is [torch.cuda.FloatTensor of size 3185x1 (GPU 0)]

s = dis.size(0) #3185
for i in range (0,s,1):
    if (dis[i,0] &lt; 0):
        dis[i,0]== 0
#There is no error but It does not work.


#2

#dis is [torch.cuda.FloatTensor of size 3185x1 (GPU 0)]

s = dis.size(0)
a = torch.zeros(s, 1).cuda()
idx = (dis &gt; a)
dis[idx] = a[idx]

AssertionError: can't compare Variable and tensor


#3

#dis is [torch.cuda.FloatTensor of size 3185x1 (GPU 0)]

s = dis.size(0)
a = torch.zeros(s, 1).cuda()
for i in range (0,s,1):
    if (dis[i,0] &lt; a[i, 0]):
        dis[i,0]==a[i, 0]

#RuntimeError: bool value of Variable objects containing non-empty      torch.cuda.ByteTensor is ambiguous


IIUC, you need to replace values smaller than 0 with 0, Just use torch.clamp, which is meant for such use cases:

dis = dis.clamp(min=0)


Example:

import torch
dis = torch.tensor([[1], [-3], [0]])
#tensor([[ 1],
#        [-3],
#        [ 0]])

dis.clamp(min=0)
#tensor([[1],
#        [0],
#        [0]])

