torch.masked_select — PyTorch 1.10.1 documentation
pytorch.org › docs › stabletorch.masked_select — PyTorch 1.10.0 documentation torch.masked_select torch.masked_select(input, mask, *, out=None) → Tensor Returns a new 1-D tensor which indexes the input tensor according to the boolean mask mask which is a BoolTensor. The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable. Note
Masking attention weights in PyTorch - GitHub Pages
juditacs.github.io › 2018/12/27 › masked-attentionDec 27, 2018 · boolean masks. Mask are the same size as the tensor being masked and only those elements are updated where the mask value is true: X=torch.arange(12).view(4,3)mask=torch.zeros((4,3),dtype=torch.uint8)# or dtype=torch.ByteTensormask[0,0]=1mask[1,1]=1mask[3,2]=1X[mask]=100print(X)>tensor([[100,1,2],[3,100,5],[6,7,8],[9,10,100]])