8000 added documentation for masked_fill and masked_fill_ · pytorch/pytorch@f3ac95b · GitHub
[go: up one dir, main page]

Skip to content

Commit f3ac95b

Browse files
added documentation for masked_fill and masked_fill_
1 parent 916e897 commit f3ac95b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

torch/_tensor_docs.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,6 +3185,15 @@ def callable(a, b) -> number
31853185
Args:
31863186
mask (BoolTensor): the boolean mask
31873187
value (float): the value to fill in with
3188+
3189+
Example:
3190+
>>> self = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
3191+
>>> mask = torch.tensor([[0, 1, 0, 1, 0], [1, 0, 1, 0, 1]], dtype=torch.bool)
3192+
>>> self.masked_fill_(mask, -1)
3193+
>>> self
3194+
tensor([[ 1, -1, 3, -1, 5],
3195+
[-1, 7, -1, 9, -1]])
3196+
31883197
""",
31893198
)
31903199

@@ -6587,6 +6596,14 @@ def callable(a, b) -> number
65876596
masked_fill(mask, value) -> Tensor
65886597
65896598
Out-of-place version of :meth:`torch.Tensor.masked_fill_`
6599+
6600+
Example:
6601+
>>> self = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
6602+
>>> mask = torch.tensor([[0, 1, 0, 1, 0], [1, 0, 1, 0, 1]], dtype=torch.bool)
6603+
>>> self.masked_fill(mask, -1)
6604+
tensor([[ 1, -1, 3, -1, 5],
6605+
[-1, 7, -1, 9, -1]])
6606+
65906607
""",
65916608
)
65926609

0 commit comments

Comments
 (0)
0