Masks for Tensors

Hello !

I’m trying to play around with PyTroch and Genetic Algorithms.
I’m implementing the evolutionary part, and for changing the weights of the Tensors, I’d like to create a mask that would only allow a small portion of the weight to be changed.

More concretely, I have a [n x m] Tensor and I want a random Tensor of the same size with only 1s and 0s.
Any recommended method ?

Thanks !

What about this?

torch.round(torch.rand(*tensor.size()))