<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreML",
  "identifier" : "/documentation/CoreML/MLTensor/replacing(with:atIndices:alongAxis:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core ML",
      "CoreML"
    ],
    "preciseIdentifier" : "s:6CoreML8MLTensorV9replacing4with9atIndices9alongAxisA2C_ACSitF"
  },
  "title" : "replacing(with:atIndices:alongAxis:)"
}
-->

# replacing(with:atIndices:alongAxis:)

Replaces slices along the specified indices with the given replacement values.

```
func replacing(with replacement: MLTensor, atIndices indices: MLTensor, alongAxis axis: Int) -> MLTensor
```

## Parameters

`replacement`

The replacement values.

`indices`

A 32-bit integer tensor containing indices to scatter values from `replacement`. Must have the same
shape as `replacement`. Must have the same shape as `self` except at `axis`.

`axis`

The axis to scatter to. Must be in the range `[-rank, rank)`.

## Return Value

The updated tensor.

## Discussion

For example:

```swift
let x = MLTensor(shape: [2, 3], scalars: [
    10, 30, 20,
    60, 40, 50
], scalarType: Float.self)
let i = MLTensor(shape: [2, 1], scalars: [
    1,
    0
], scalarType: Int32.self)
let updates = MLTensor(shape: [2, 1], scalars: [
    99,
    99
], scalarType: Float.self)
let y = x.replacing(atIndices: i, with: updates, alongAxis: 1)
// [[10, 99, 20],
//  [99, 40, 50]]
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)