---
title: "ClikaRT::ops::masked_fill"
sidebar_label: "masked_fill"
description: "Replace the elements of input where mask is true with value. mask is Bool and broadcasts to input's shape; value is a literal or a 0-D Tensor."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--function">function</span>

## masked\_fill() {#masked_fill}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`masked_fill`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `mask`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ScalarOrTensor`](../ScalarOrTensor.md) `value`<br />
)

</div>

Replace the elements of `input` where `mask` is true with `value`.

`mask` is Bool and broadcasts to `input`'s shape; `value` is a literal or a 0-D [Tensor](../Tensor.md).

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when `mask` is not Bool or does not broadcast to `input` (`code_name()` carries the reason).

**Returns:** a new tensor shaped like `input`.

```cpp
auto masked = ClikaRT::ops::masked_fill(scores, pad_mask, -1e9);
```

<div class="api-declared">

Declared in `ClikaRT/compute/ops.h`, line 2582

</div>
