---
title: "replacing(with:where:)"
framework: coreml
role: symbol
role_heading: Instance Method
path: "coreml/mltensor/replacing(with:where:)"
---

# replacing(with:where:)

Returns a new tensor replacing values from other with the corresponding element in self where the associated element in mask is true.

## Declaration

```swift
func replacing(with replacement: MLTensor, where mask: MLTensor) -> MLTensor
```

## Parameters

- `replacement`: The replacement values where mask is true.
- `mask`: The Boolean mask that determines whether the corresponding element / row should be taken from self (if the element in mask is false) or other (if true).

## Return Value

Return Value A new tensor of the same shape and type as self.

## Discussion

Discussion For example: let x = MLTensor([1, 2, 3], scalarType: Float.self) let y = MLTensor([4, 5, 6], scalarType: Float.self) let mask = MLTensor([false, true, false]) let z = x.replacing(with: y, where: mask) await z.shapedArray(of: Float.self) // is [1, 5, 3]

## See Also

### Replacing the tensor values

- [replacing(atIndices:with:alongAxis:)](coreml/mltensor/replacing(atindices:with:alongaxis:).md)
- [replacing(with:atIndices:alongAxis:)](coreml/mltensor/replacing(with:atindices:alongaxis:).md)
