x= torch.randn(2,2)
print x
x[x<0] = 0
print x
Hi, I’m confused to how to assign for bool index tensor. where is source code of the bool index tensor assignment?
x[x<0] seems to be no dimension, Does x and x[x<0] share memory?
x= torch.randn(2,2)
print x
x[x<0] = 0
print x
Hi, I’m confused to how to assign for bool index tensor. where is source code of the bool index tensor assignment?
x[x<0] seems to be no dimension, Does x and x[x<0] share memory?
why are you looking for the source code for this operation? (just curious). It’s somewhere inside C++, i can pull it up.
x[x<0] seems to be no dimension, Does x and x[x<0] share memory?
I dont understand your question, what do you mean by “no dimension”?
sorry, i am wrong about the dimension of x[x<0]. When i x is 2D, x[x<0] seems to be one dimension.
>>> x = torch.randn(2,2)
>>> x.shape
(2L, 2L)
>>> x[x<0]
-1.9025
-0.2359
-0.3980
[torch.FloatTensor of size 3]
>>> x[x<0].shape
(3L,)
>>> x[x<0].size()
(3L,)
>>> x[x<0]
-1.9025
-0.2359
-0.3980
[torch.FloatTensor of size 3]
>>> x[x<0].size()
(3L,)
i’m just curious ahout how to implement assignment for bool index tensor. Please pull it up.
Assignment via [] is implemented here:
The case where the “key” is a ByteTensor (x < 0 returns a ByteTensor of 0s and 1s in PyTorch) is in the if (mask)
section.