# ScatterElements#

## ScatterElements - 16#

Version

• domain: main

• since_version: 16

• function: False

• support_level: SupportType.COMMON

• shape inference: True

This version of the operator has been available since version 16.

Summary

ScatterElements takes three inputs data, updates, and indices of the same rank r >= 1 and an optional attribute axis that identifies an axis of data (by default, the outer-most axis, that is axis 0). The output of the operation is produced by creating a copy of the input data, and then updating its value to values specified by updates at specific index positions specified by indices. Its output shape is the same as the shape of data.

For each entry in updates, the target index in data is obtained by combining the corresponding entry in indices with the index of the entry itself: the index-value for dimension = axis is obtained from the value of the corresponding entry in indices and the index-value for dimension != axis is obtained from the index of the entry itself.

reduction allows specification of an optional reduction operation, which is applied to all values in updates tensor into output at the specified indices. In cases where reduction is set to “none”, indices should not have duplicate entries: that is, if idx1 != idx2, then indices[idx1] != indices[idx2]. For instance, in a 2-D tensor case, the update corresponding to the [i][j] entry is performed as below:

```output[indices[i][j]][j] = updates[i][j] if axis = 0,
output[i][indices[i][j]] = updates[i][j] if axis = 1,
```

When reduction is set to “add”, the update corresponding to the [i][j] entry is performed as below:

```output[indices[i][j]][j] += updates[i][j] if axis = 0,
output[i][indices[i][j]] += updates[i][j] if axis = 1,
```

When reduction is set to “mul”, the update corresponding to the [i][j] entry is performed as below:

```output[indices[i][j]][j] *= updates[i][j] if axis = 0,
output[i][indices[i][j]] *= updates[i][j] if axis = 1,
```

This operator is the inverse of GatherElements. It is similar to Torch’s Scatter operation.

Example 1:

```data = [
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
]
indices = [
[1, 0, 2],
[0, 2, 1],
]
[1.0, 1.1, 1.2],
[2.0, 2.1, 2.2],
]
output = [
[2.0, 1.1, 0.0]
[1.0, 0.0, 2.2]
[0.0, 2.1, 1.2]
]
```

Example 2:

```data = [[1.0, 2.0, 3.0, 4.0, 5.0]]
indices = [[1, 3]]
updates = [[1.1, 2.1]]
axis = 1
output = [[1.0, 1.1, 3.0, 2.1, 5.0]]
```

Attributes

• axis: Which axis to scatter on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data). Default value is `0`.

• reduction: Type of reduction to apply: none (default), add, mul. ‘none’: no reduction applied. ‘add’: reduction using the addition operation. ‘mul’: reduction using the multiplication operation. Default value is `'none'`.

Inputs

• data (heterogeneous) - T: Tensor of rank r >= 1.

• indices (heterogeneous) - Tind: Tensor of int32/int64 indices, of r >= 1 (same rank as input). All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.

• updates (heterogeneous) - T: Tensor of rank r >=1 (same rank and shape as indices)

Outputs

• output (heterogeneous) - T: Tensor of rank r >= 1 (same rank as input).

Type Constraints

• T in ( tensor(bfloat16), tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Input and output types can be of any tensor type.

• Tind in ( tensor(int32), tensor(int64) ): Constrain indices to integer types

Examples

_scatter_elements_without_axis

```node = onnx.helper.make_node(
'ScatterElements',
outputs=['y'],
)
data = np.zeros((3, 3), dtype=np.float32)
indices = np.array([[1, 0, 2], [0, 2, 1]], dtype=np.int64)
updates = np.array([[1.0, 1.1, 1.2], [2.0, 2.1, 2.2]], dtype=np.float32)

y = scatter_elements(data, indices, updates)
# print(y) produces
# [[2.0, 1.1, 0.0],
#  [1.0, 0.0, 2.2],
#  [0.0, 2.1, 1.2]]

expect(node, inputs=[data, indices, updates], outputs=[y],
name='test_scatter_elements_without_axis')
```

_scatter_elements_with_axis

```axis = 1
node = onnx.helper.make_node(
'ScatterElements',
outputs=['y'],
axis=axis,
)
data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32)
indices = np.array([[1, 3]], dtype=np.int64)
updates = np.array([[1.1, 2.1]], dtype=np.float32)

y = scatter_elements(data, indices, updates, axis)
# print(y) produces
# [[1.0, 1.1, 3.0, 2.1, 5.0]]

expect(node, inputs=[data, indices, updates], outputs=[y],
name='test_scatter_elements_with_axis')
```

_scatter_elements_with_negative_indices

```axis = 1
node = onnx.helper.make_node(
'ScatterElements',
outputs=['y'],
axis=axis,
)
data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32)
indices = np.array([[1, -3]], dtype=np.int64)
updates = np.array([[1.1, 2.1]], dtype=np.float32)

y = scatter_elements(data, indices, updates, axis)
# print(y) produces
# [[1.0, 1.1, 2.1, 4.0, 5.0]]

expect(node, inputs=[data, indices, updates], outputs=[y],
name='test_scatter_elements_with_negative_indices')
```

_scatter_elements_with_duplicate_indices

```axis = 1
node = onnx.helper.make_node(
'ScatterElements',
outputs=['y'],
axis=axis,
)
data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32)
indices = np.array([[1, 1]], dtype=np.int64)
updates = np.array([[1.1, 2.1]], dtype=np.float32)

y = scatter_elements(data, indices, updates, axis, reduction='add')
# print(y) produces
# [[1.0, 5.2, 3.0, 4.0, 5.0]]

expect(node, inputs=[data, indices, updates], outputs=[y],
name='test_scatter_elements_with_duplicate_indices')
```

Differences

 `0` `0` `ScatterElements takes three inputs data, updates, and indices of the same` `ScatterElements takes three inputs data, updates, and indices of the same` `1` `1` `rank r >= 1 and an optional attribute axis that identifies an axis of data` `rank r >= 1 and an optional attribute axis that identifies an axis of data` `2` `2` `(by default, the outer-most axis, that is axis 0). The output of the operation` `(by default, the outer-most axis, that is axis 0). The output of the operation` `3` `3` `is produced by creating a copy of the input data, and then updating its value` `is produced by creating a copy of the input data, and then updating its value` `4` `4` `to values specified by updates at specific index positions specified by` `to values specified by updates at specific index positions specified by` `5` `5` `indices. Its output shape is the same as the shape of data.` `indices. Its output shape is the same as the shape of data.` `6` `6` `7` `7` `For each entry in updates, the target index in data is obtained by combining` `For each entry in updates, the target index in data is obtained by combining` `8` `8` `the corresponding entry in indices with the index of the entry itself: the` `the corresponding entry in indices with the index of the entry itself: the` `9` `9` `index-value for dimension = axis is obtained from the value of the corresponding` `index-value for dimension = axis is obtained from the value of the corresponding` `10` `10` `entry in indices and the index-value for dimension != axis is obtained from the` `entry in indices and the index-value for dimension != axis is obtained from the` `11` `11` `index of the entry itself.` `index of the entry itself.` `12` `12` `13` `reduction allows specification of an optional reduction operation, which is applied to all values in updates` `14` `tensor into output at the specified indices.` `15` `In cases where reduction is set to "none", indices should not have duplicate entries: that is, if idx1 != idx2,` `16` `then indices[idx1] != indices[idx2]. For instance, in a 2-D tensor case, the update` `17` `corresponding to the [i][j] entry is performed as below:` `18` `::` `19` `20` ` output[indices[i][j]][j] = updates[i][j] if axis = 0,` `21` ` output[i][indices[i][j]] = updates[i][j] if axis = 1,` `22` `13` `23` `For instance, in a 2-D tensor case, the update corresponding to the [i][j] entry` `When reduction is set to "add", the update corresponding to the [i][j] entry is performed as below:` `24` `::` `25` `26` ` output[indices[i][j]][j] += updates[i][j] if axis = 0,` `27` ` output[i][indices[i][j]] += updates[i][j] if axis = 1,` `28` `14` `29` `is performed as below:` `When reduction is set to "mul", the update corresponding to the [i][j] entry is performed as below:` `15` `30` `::` `::` `16` `31` `17` `32` ` output[indices[i][j]][j] = updates[i][j] if axis = 0,` ` output[indices[i][j]][j] *= updates[i][j] if axis = 0,` `18` `33` ` output[i][indices[i][j]] = updates[i][j] if axis = 1,` ` output[i][indices[i][j]] *= updates[i][j] if axis = 1,` `19` `34` `20` `35` `This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation.` `This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation.` `21` `36` `22` `37` `Example 1:` `Example 1:` `23` `38` `::` `::` `24` `39` `25` `40` ` data = [` ` data = [` `26` `41` ` [0.0, 0.0, 0.0],` ` [0.0, 0.0, 0.0],` `27` `42` ` [0.0, 0.0, 0.0],` ` [0.0, 0.0, 0.0],` `28` `43` ` [0.0, 0.0, 0.0],` ` [0.0, 0.0, 0.0],` `29` `44` ` ]` ` ]` `30` `45` ` indices = [` ` indices = [` `31` `46` ` [1, 0, 2],` ` [1, 0, 2],` `32` `47` ` [0, 2, 1],` ` [0, 2, 1],` `33` `48` ` ]` ` ]` `34` `49` ` updates = [` ` updates = [` `35` `50` ` [1.0, 1.1, 1.2],` ` [1.0, 1.1, 1.2],` `36` `51` ` [2.0, 2.1, 2.2],` ` [2.0, 2.1, 2.2],` `37` `52` ` ]` ` ]` `38` `53` ` output = [` ` output = [` `39` `54` ` [2.0, 1.1, 0.0]` ` [2.0, 1.1, 0.0]` `40` `55` ` [1.0, 0.0, 2.2]` ` [1.0, 0.0, 2.2]` `41` `56` ` [0.0, 2.1, 1.2]` ` [0.0, 2.1, 1.2]` `42` `57` ` ]` ` ]` `43` `58` `44` `59` `Example 2:` `Example 2:` `45` `60` `::` `::` `46` `61` `47` `62` ` data = [[1.0, 2.0, 3.0, 4.0, 5.0]]` ` data = [[1.0, 2.0, 3.0, 4.0, 5.0]]` `48` `63` ` indices = [[1, 3]]` ` indices = [[1, 3]]` `49` `64` ` updates = [[1.1, 2.1]]` ` updates = [[1.1, 2.1]]` `50` `65` ` axis = 1` ` axis = 1` `51` `66` ` output = [[1.0, 1.1, 3.0, 2.1, 5.0]]` ` output = [[1.0, 1.1, 3.0, 2.1, 5.0]]` `52` `67` `53` `68` `**Attributes**` `**Attributes**` `54` `69` `55` `70` `* **axis**:` `* **axis**:` `56` `71` ` Which axis to scatter on. Negative value means counting dimensions` ` Which axis to scatter on. Negative value means counting dimensions` `57` `72` ` from the back. Accepted range is [-r, r-1] where r = rank(data). Default value is 0.` ` from the back. Accepted range is [-r, r-1] where r = rank(data). Default value is 0.` `73` `* **reduction**:` `74` ` Type of reduction to apply: none (default), add, mul. 'none': no` `75` ` reduction applied. 'add': reduction using the addition operation.` `76` ` 'mul': reduction using the multiplication operation. Default value is 'none'.` `58` `77` `59` `78` `**Inputs**` `**Inputs**` `60` `79` `61` `80` `* **data** (heterogeneous) - **T**:` `* **data** (heterogeneous) - **T**:` `62` `81` ` Tensor of rank r >= 1.` ` Tensor of rank r >= 1.` `63` `82` `* **indices** (heterogeneous) - **Tind**:` `* **indices** (heterogeneous) - **Tind**:` `64` `83` ` Tensor of int32/int64 indices, of r >= 1 (same rank as input). All` ` Tensor of int32/int64 indices, of r >= 1 (same rank as input). All` `65` `84` ` index values are expected to be within bounds [-s, s-1] along axis` ` index values are expected to be within bounds [-s, s-1] along axis` `66` `85` ` of size s. It is an error if any of the index values are out of` ` of size s. It is an error if any of the index values are out of` `67` `86` ` bounds.` ` bounds.` `68` `87` `* **updates** (heterogeneous) - **T**:` `* **updates** (heterogeneous) - **T**:` `69` `88` ` Tensor of rank r >=1 (same rank and shape as indices)` ` Tensor of rank r >=1 (same rank and shape as indices)` `70` `89` `71` `90` `**Outputs**` `**Outputs**` `72` `91` `73` `92` `* **output** (heterogeneous) - **T**:` `* **output** (heterogeneous) - **T**:` `74` `93` ` Tensor of rank r >= 1 (same rank as input).` ` Tensor of rank r >= 1 (same rank as input).` `75` `94` `76` `95` `**Type Constraints**` `**Type Constraints**` `77` `96` `78` `97` `* **T** in (` `* **T** in (` `79` `98` ` tensor(bfloat16),` ` tensor(bfloat16),` `80` `99` ` tensor(bool),` ` tensor(bool),` `81` `100` ` tensor(complex128),` ` tensor(complex128),` `82` `101` ` tensor(complex64),` ` tensor(complex64),` `83` `102` ` tensor(double),` ` tensor(double),` `84` `103` ` tensor(float),` ` tensor(float),` `85` `104` ` tensor(float16),` ` tensor(float16),` `86` `105` ` tensor(int16),` ` tensor(int16),` `87` `106` ` tensor(int32),` ` tensor(int32),` `88` `107` ` tensor(int64),` ` tensor(int64),` `89` `108` ` tensor(int8),` ` tensor(int8),` `90` `109` ` tensor(string),` ` tensor(string),` `91` `110` ` tensor(uint16),` ` tensor(uint16),` `92` `111` ` tensor(uint32),` ` tensor(uint32),` `93` `112` ` tensor(uint64),` ` tensor(uint64),` `94` `113` ` tensor(uint8)` ` tensor(uint8)` `95` `114` ` ):` ` ):` `96` `115` ` Input and output types can be of any tensor type.` ` Input and output types can be of any tensor type.` `97` `116` `* **Tind** in (` `* **Tind** in (` `98` `117` ` tensor(int32),` ` tensor(int32),` `99` `118` ` tensor(int64)` ` tensor(int64)` `100` `119` ` ):` ` ):` `101` `120` ` Constrain indices to integer types` ` Constrain indices to integer types`

## ScatterElements - 13#

Version

• domain: main

• since_version: 13

• function: False

• support_level: SupportType.COMMON

• shape inference: True

This version of the operator has been available since version 13.

Summary

ScatterElements takes three inputs data, updates, and indices of the same rank r >= 1 and an optional attribute axis that identifies an axis of data (by default, the outer-most axis, that is axis 0). The output of the operation is produced by creating a copy of the input data, and then updating its value to values specified by updates at specific index positions specified by indices. Its output shape is the same as the shape of data.

For each entry in updates, the target index in data is obtained by combining the corresponding entry in indices with the index of the entry itself: the index-value for dimension = axis is obtained from the value of the corresponding entry in indices and the index-value for dimension != axis is obtained from the index of the entry itself.

For instance, in a 2-D tensor case, the update corresponding to the [i][j] entry is performed as below:

```output[indices[i][j]][j] = updates[i][j] if axis = 0,
output[i][indices[i][j]] = updates[i][j] if axis = 1,
```

This operator is the inverse of GatherElements. It is similar to Torch’s Scatter operation.

Example 1:

```data = [
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
]
indices = [
[1, 0, 2],
[0, 2, 1],
]
[1.0, 1.1, 1.2],
[2.0, 2.1, 2.2],
]
output = [
[2.0, 1.1, 0.0]
[1.0, 0.0, 2.2]
[0.0, 2.1, 1.2]
]
```

Example 2:

```data = [[1.0, 2.0, 3.0, 4.0, 5.0]]
indices = [[1, 3]]
updates = [[1.1, 2.1]]
axis = 1
output = [[1.0, 1.1, 3.0, 2.1, 5.0]]
```

Attributes

• axis: Which axis to scatter on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data). Default value is `0`.

Inputs

• data (heterogeneous) - T: Tensor of rank r >= 1.

• indices (heterogeneous) - Tind: Tensor of int32/int64 indices, of r >= 1 (same rank as input). All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.

• updates (heterogeneous) - T: Tensor of rank r >=1 (same rank and shape as indices)

Outputs

• output (heterogeneous) - T: Tensor of rank r >= 1 (same rank as input).

Type Constraints

• T in ( tensor(bfloat16), tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Input and output types can be of any tensor type.

• Tind in ( tensor(int32), tensor(int64) ): Constrain indices to integer types

Differences

 `0` `0` `ScatterElements takes three inputs data, updates, and indices of the same` `ScatterElements takes three inputs data, updates, and indices of the same` `1` `1` `rank r >= 1 and an optional attribute axis that identifies an axis of data` `rank r >= 1 and an optional attribute axis that identifies an axis of data` `2` `2` `(by default, the outer-most axis, that is axis 0). The output of the operation` `(by default, the outer-most axis, that is axis 0). The output of the operation` `3` `3` `is produced by creating a copy of the input data, and then updating its value` `is produced by creating a copy of the input data, and then updating its value` `4` `4` `to values specified by updates at specific index positions specified by` `to values specified by updates at specific index positions specified by` `5` `5` `indices. Its output shape is the same as the shape of data.` `indices. Its output shape is the same as the shape of data.` `6` `6` `7` `7` `For each entry in updates, the target index in data is obtained by combining` `For each entry in updates, the target index in data is obtained by combining` `8` `8` `the corresponding entry in indices with the index of the entry itself: the` `the corresponding entry in indices with the index of the entry itself: the` `9` `9` `index-value for dimension = axis is obtained from the value of the corresponding` `index-value for dimension = axis is obtained from the value of the corresponding` `10` `10` `entry in indices and the index-value for dimension != axis is obtained from the` `entry in indices and the index-value for dimension != axis is obtained from the` `11` `11` `index of the entry itself.` `index of the entry itself.` `12` `12` `13` `13` `For instance, in a 2-D tensor case, the update corresponding to the [i][j] entry` `For instance, in a 2-D tensor case, the update corresponding to the [i][j] entry` `14` `14` `is performed as below:` `is performed as below:` `15` `15` `::` `::` `16` `16` `17` `17` ` output[indices[i][j]][j] = updates[i][j] if axis = 0,` ` output[indices[i][j]][j] = updates[i][j] if axis = 0,` `18` `18` ` output[i][indices[i][j]] = updates[i][j] if axis = 1,` ` output[i][indices[i][j]] = updates[i][j] if axis = 1,` `19` `19` `20` `20` `This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation.` `This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation.` `21` `21` `22` `22` `Example 1:` `Example 1:` `23` `23` `::` `::` `24` `24` `25` `25` ` data = [` ` data = [` `26` `26` ` [0.0, 0.0, 0.0],` ` [0.0, 0.0, 0.0],` `27` `27` ` [0.0, 0.0, 0.0],` ` [0.0, 0.0, 0.0],` `28` `28` ` [0.0, 0.0, 0.0],` ` [0.0, 0.0, 0.0],` `29` `29` ` ]` ` ]` `30` `30` ` indices = [` ` indices = [` `31` `31` ` [1, 0, 2],` ` [1, 0, 2],` `32` `32` ` [0, 2, 1],` ` [0, 2, 1],` `33` `33` ` ]` ` ]` `34` `34` ` updates = [` ` updates = [` `35` `35` ` [1.0, 1.1, 1.2],` ` [1.0, 1.1, 1.2],` `36` `36` ` [2.0, 2.1, 2.2],` ` [2.0, 2.1, 2.2],` `37` `37` ` ]` ` ]` `38` `38` ` output = [` ` output = [` `39` `39` ` [2.0, 1.1, 0.0]` ` [2.0, 1.1, 0.0]` `40` `40` ` [1.0, 0.0, 2.2]` ` [1.0, 0.0, 2.2]` `41` `41` ` [0.0, 2.1, 1.2]` ` [0.0, 2.1, 1.2]` `42` `42` ` ]` ` ]` `43` `43` `44` `44` `Example 2:` `Example 2:` `45` `45` `::` `::` `46` `46` `47` `47` ` data = [[1.0, 2.0, 3.0, 4.0, 5.0]]` ` data = [[1.0, 2.0, 3.0, 4.0, 5.0]]` `48` `48` ` indices = [[1, 3]]` ` indices = [[1, 3]]` `49` `49` ` updates = [[1.1, 2.1]]` ` updates = [[1.1, 2.1]]` `50` `50` ` axis = 1` ` axis = 1` `51` `51` ` output = [[1.0, 1.1, 3.0, 2.1, 5.0]]` ` output = [[1.0, 1.1, 3.0, 2.1, 5.0]]` `52` `52` `53` `53` `**Attributes**` `**Attributes**` `54` `54` `55` `55` `* **axis**:` `* **axis**:` `56` `56` ` Which axis to scatter on. Negative value means counting dimensions` ` Which axis to scatter on. Negative value means counting dimensions` `57` `57` ` from the back. Accepted range is [-r, r-1] where r = rank(data). Default value is 0.` ` from the back. Accepted range is [-r, r-1] where r = rank(data). Default value is 0.` `58` `58` `59` `59` `**Inputs**` `**Inputs**` `60` `60` `61` `61` `* **data** (heterogeneous) - **T**:` `* **data** (heterogeneous) - **T**:` `62` `62` ` Tensor of rank r >= 1.` ` Tensor of rank r >= 1.` `63` `63` `* **indices** (heterogeneous) - **Tind**:` `* **indices** (heterogeneous) - **Tind**:` `64` `64` ` Tensor of int32/int64 indices, of r >= 1 (same rank as input). All` ` Tensor of int32/int64 indices, of r >= 1 (same rank as input). All` `65` `65` ` index values are expected to be within bounds [-s, s-1] along axis` ` index values are expected to be within bounds [-s, s-1] along axis` `66` `66` ` of size s. It is an error if any of the index values are out of` ` of size s. It is an error if any of the index values are out of` `67` `67` ` bounds.` ` bounds.` `68` `68` `* **updates** (heterogeneous) - **T**:` `* **updates** (heterogeneous) - **T**:` `69` `69` ` Tensor of rank r >=1 (same rank and shape as indices)` ` Tensor of rank r >=1 (same rank and shape as indices)` `70` `70` `71` `71` `**Outputs**` `**Outputs**` `72` `72` `73` `73` `* **output** (heterogeneous) - **T**:` `* **output** (heterogeneous) - **T**:` `74` `74` ` Tensor of rank r >= 1 (same rank as input).` ` Tensor of rank r >= 1 (same rank as input).` `75` `75` `76` `76` `**Type Constraints**` `**Type Constraints**` `77` `77` `78` `78` `* **T** in (` `* **T** in (` `79` ` tensor(bfloat16),` `79` `80` ` tensor(bool),` ` tensor(bool),` `80` `81` ` tensor(complex128),` ` tensor(complex128),` `81` `82` ` tensor(complex64),` ` tensor(complex64),` `82` `83` ` tensor(double),` ` tensor(double),` `83` `84` ` tensor(float),` ` tensor(float),` `84` `85` ` tensor(float16),` ` tensor(float16),` `85` `86` ` tensor(int16),` ` tensor(int16),` `86` `87` ` tensor(int32),` ` tensor(int32),` `87` `88` ` tensor(int64),` ` tensor(int64),` `88` `89` ` tensor(int8),` ` tensor(int8),` `89` `90` ` tensor(string),` ` tensor(string),` `90` `91` ` tensor(uint16),` ` tensor(uint16),` `91` `92` ` tensor(uint32),` ` tensor(uint32),` `92` `93` ` tensor(uint64),` ` tensor(uint64),` `93` `94` ` tensor(uint8)` ` tensor(uint8)` `94` `95` ` ):` ` ):` `95` `96` ` Input and output types can be of any tensor type.` ` Input and output types can be of any tensor type.` `96` `97` `* **Tind** in (` `* **Tind** in (` `97` `98` ` tensor(int32),` ` tensor(int32),` `98` `99` ` tensor(int64)` ` tensor(int64)` `99` `100` ` ):` ` ):` `100` `101` ` Constrain indices to integer types` ` Constrain indices to integer types`

## ScatterElements - 11#

Version

• domain: main

• since_version: 11

• function: False

• support_level: SupportType.COMMON

• shape inference: True

This version of the operator has been available since version 11.

Summary

ScatterElements takes three inputs data, updates, and indices of the same rank r >= 1 and an optional attribute axis that identifies an axis of data (by default, the outer-most axis, that is axis 0). The output of the operation is produced by creating a copy of the input data, and then updating its value to values specified by updates at specific index positions specified by indices. Its output shape is the same as the shape of data.

For each entry in updates, the target index in data is obtained by combining the corresponding entry in indices with the index of the entry itself: the index-value for dimension = axis is obtained from the value of the corresponding entry in indices and the index-value for dimension != axis is obtained from the index of the entry itself.

For instance, in a 2-D tensor case, the update corresponding to the [i][j] entry is performed as below:

```output[indices[i][j]][j] = updates[i][j] if axis = 0,
output[i][indices[i][j]] = updates[i][j] if axis = 1,
```

This operator is the inverse of GatherElements. It is similar to Torch’s Scatter operation.

Example 1:

```data = [
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
]
indices = [
[1, 0, 2],
[0, 2, 1],
]
[1.0, 1.1, 1.2],
[2.0, 2.1, 2.2],
]
output = [
[2.0, 1.1, 0.0]
[1.0, 0.0, 2.2]
[0.0, 2.1, 1.2]
]
```

Example 2:

```data = [[1.0, 2.0, 3.0, 4.0, 5.0]]
indices = [[1, 3]]
updates = [[1.1, 2.1]]
axis = 1
output = [[1.0, 1.1, 3.0, 2.1, 5.0]]
```

Attributes

• axis: Which axis to scatter on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data). Default value is `0`.

Inputs

• data (heterogeneous) - T: Tensor of rank r >= 1.

• indices (heterogeneous) - Tind: Tensor of int32/int64 indices, of r >= 1 (same rank as input). All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.

• updates (heterogeneous) - T: Tensor of rank r >=1 (same rank and shape as indices)

Outputs

• output (heterogeneous) - T: Tensor of rank r >= 1 (same rank as input).

Type Constraints

• T in ( tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Input and output types can be of any tensor type.

• Tind in ( tensor(int32), tensor(int64) ): Constrain indices to integer types