ameliatqy
(Amelia)
February 12, 2020, 9:58pm
#1
Hey guys,

How can I create a mask based on comparing numerical values? For example, I want the mask to be 1 when the first value in the second dimension is bigger than the second value in the second dimension.

Input: [[1, 2], [4, 1], [3, 1], [0, 1]]
Output Mask: [0, 1, 1, 0]

Input: [[22, 11], [90,80], [15, 19], [6, 8]]
Output Mask: [1, 1, 0, 0]

Is this possible? Thank you for your help in advance!

EDIT: Corrected second example

ptrblck
February 13, 2020, 5:22am
#2
This should work:

```
x = torch.tensor([[1, 2], [4, 1], [3, 1], [0, 1]])
res = (x[:, 0] > x[:, 1]).long()
x = torch.tensor([[22, 11], [90,80], [15, 19], [6, 8]])
res = (x[:, 0] > x[:, 1]).long()
```

The second output should probably be `[1, 1, 0, 0]`

?

1 Like

ameliatqy
(Amelia)
February 13, 2020, 5:57pm
#3
It does work And you are right about the second example, I will correct it. Thank you for your help!