How to binarize a Variable?

For example, I have a tensor with random values. For each element, set it 1 if its value is larger than 0.5, else set it 0.

X > 0.5

Creates a binary mask if X is your tensor. You may need to cast it to an appropriate type.

Thank you, justusschock!