fn
masked_fill
→Tensormasked_fill(input: Tensor, mask: Tensor, value: float)Return input with positions where mask is True set to value.
The mask must be broadcast-compatible with input. Out-of-place:
a fresh tensor is returned; input is not modified.
Parameters
inputTensorSource tensor.
maskTensorBoolean tensor broadcastable to
input.valuefloatScalar fill value.
Returns
TensorTensor of the same shape and dtype as input.
Notes
Often used to apply attention masks:
Examples
>>> import lucid
>>> x = lucid.tensor([1.0, 2.0, 3.0])
>>> m = lucid.tensor([True, False, True])
>>> lucid.masked_fill(x, m, 0.0)
Tensor([0., 2., 0.])