masked_fill

tripy.masked_fill(input: Tensor, mask: Tensor, value: Number) Tensor[source]

Returns a new tensor filled with value where mask is True and elements from the input tensor otherwise.

Parameters:
  • input (Tensor) – [dtype=T1] The input tensor.

  • mask (Tensor) – [dtype=T2] The mask tensor.

  • value (Number) – the value to fill with. This will be casted to match the data type of the input tensor.

Returns:

[dtype=T1] A new tensor of the same shape as the input tensor.

Return type:

Tensor

TYPE CONSTRAINTS:
Example
Example
1mask = tp.Tensor([[True, False], [True, True]])
2input = tp.zeros([2, 2])
3output = tp.masked_fill(input, mask, -1.0)
>>> mask
tensor(
    [[True, False],
     [True, True]], 
    dtype=bool, loc=gpu:0, shape=(2, 2))
>>> input
tensor(
    [[0.0000, 0.0000],
     [0.0000, 0.0000]], 
    dtype=float32, loc=gpu:0, shape=(2, 2))
>>> output
tensor(
    [[-1.0000, 0.0000],
     [-1.0000, -1.0000]], 
    dtype=float32, loc=gpu:0, shape=(2, 2))