masked_fill¶
- tripy.masked_fill(input: Tensor, mask: Tensor, value: Number) Tensor [source]¶
Returns a new tensor filled with
value
wheremask
isTrue
and elements from the input tensor otherwise.- Parameters:
- Returns:
[dtype=T1] A new tensor of the same shape as the input tensor.
- Return type:
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))