!37815 modify the documents for op ScatterNd

Merge pull request !37815 from DeshiChen/code_docs_scatternd_master
This commit is contained in:
i-robot 2022-07-12 03:09:19 +00:00 committed by Gitee
commit 247a9a0b75
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 26 additions and 21 deletions

View File

@ -5,13 +5,17 @@ mindspore.ops.scatter_nd
根据指定的索引将更新值散布到新Tensor上。
使用给定的 `shape` 创建一个空Tensor并将 `updates` 的值通过索引来设置空Tensor的值。空Tensor的秩为 :math:`P` `indices` 的秩为 :math:`Q` :math:`Q \ge 2` 。
使用给定的 `shape` 创建一个空Tensor并将 `updates` 的值通过索引 `indices` 来设置空Tensor的值。空Tensor的秩为 :math:`P` `indices` 的秩为 :math:`Q` 。
`indices` 的shape为 :math:`(i_0, i_1, ..., i_{Q-2}, N)` :math:`N \le P` 。
`shape`:math:`(s_0, s_1, ..., s_{P-1})` 其中 :math:`P \ge 1` 。
`indices`最后一个维度(长度为 :math:`N` 表示沿着空Tensor的 :math:`N` 个维度进行切片
`indices`shape为 :math:`(i_0, i_1, ..., i_{Q-2}, N)` 其中 :math:`Q \ge 2`:math:`N \le P`
`updates` 表示秩为 :math:`Q-1+P-N` 的Tensorshape为 :math:`(i_0, i_1, ..., i_{Q-2}, shape_N, ..., shape_{P-1})`
`indices` 的最后一个维度(长度为 :math:`N` 表示沿着空Tensor的第 :math:`N` 个维度进行切片。
`updates` 是一个秩为 :math:`Q-1+P-N` 的Tensorshape为 :math:`(i_0, i_1, ..., i_{Q-2}, s_N, s_{N+1}, ..., s_{P-1})`
如果 `indices` 包含重复的下标,则 `updates` 的值会被累加到同一个位置上。
在秩为3的第一个维度中插入两个新值矩阵的计算过程如下图所示
@ -19,9 +23,9 @@ mindspore.ops.scatter_nd
**参数:**
- **indices** (Tensor) - 指定新Tensor中散布的索引数据类型为int32或int64。索引的秩须至少为2并且 :math:`indices\_shape[-1] \le len(shape)`
- **updates** (Tensor) - 指定更新Tensorshape为 :math:`indices\_shape[:-1] + shape[indices\_shape[-1]:]`
- **shape** (tuple[int]) - 指定输出Tensor的shape数据类型与索引相同。 `shape`:math:`(x_1, x_2, ..., x_R)``shape` 的长度大于或等于2。换句话说 `shape` 至少是 :math:`(x_1, x_2)` ,且 `shape` 中的任何元素的值都必须大于等于1。也就是说, :math:`x_1 \ge 1` :math:`x_2 \ge 1`
- **indices** (Tensor) - 指定新Tensor中散布的索引数据类型为int32或int64。索引的秩须至少为2并且 `indices.shape[-1] <= len(shape)`
- **updates** (Tensor) - 指定更新Tensorshape为 `indices.shape[:-1] + shape[indices.shape[-1]:]`
- **shape** (tuple[int]) - 指定输出Tensor的shape数据类型与 `indices` 相同。 `shape` 不能为空,且 `shape` 中的任何元素的值都必须大于等于1。
**返回:**

View File

@ -1400,31 +1400,32 @@ def scatter_nd(indices, updates, shape):
Scatters a tensor into a new tensor depending on the specified indices.
Creates an empty tensor with the given `shape`, and set values by scattering the update tensor
depending on indices. The empty tensor has rank :math:`P` and `indices` has rank :math:`Q` where :math:`Q \ge 2`.
depending on indices. The empty tensor has rank :math:`P` and `indices` has rank :math:`Q`.
`indices` has shape :math:`(i_0, i_1, ..., i_{Q-2}, N)` where :math:`N \le P`.
The `shape` is :math:`(s_0, s_1, ..., s_{P-1})`, where :math:`P \ge 1`.
`indices` has shape :math:`(i_0, i_1, ..., i_{Q-2}, N)`, where :math:`Q \ge 2` and :math:`N \le P`.
The last dimension of `indices` (with length :math:`N` ) indicates slices along the :math:`N` th dimension of the
empty tensor.
`updates` is a tensor of rank :math:`Q-1+P-N`,
its shape is: :math:`(i_0, i_1, ..., i_{Q-2}, shape_N, ..., shape_{P-1})`.
`updates` is a tensor of rank :math:`Q-1+P-N`, and
its shape is :math:`(i_0, i_1, ..., i_{Q-2}, s_N, s_{N+1}, ..., s_{P-1})`.
The following figure shows the calculation process of inserting two slices in the first dimension of a rank-3
with two matrices of new values:
If `indices` contains duplicates, the duplicate `updates` are summed.
The following figure shows the calculation process of inserting two new value matrices into the first dimension
with rank-3:
.. image:: ScatterNd.png
Args:
indices (Tensor): The index of scattering in the new tensor with int32 or int64 data type.
The rank of indices must be at least 2 and :math:`indices\_shape[-1] \le len(shape)`.
updates (Tensor): The source Tensor to be scattered.
It has shape :math:`indices\_shape[:-1] + shape[indices\_shape[-1]:]`.
indices (Tensor): Define the index of scattering in the new tensor with int32 or int64 data type.
The rank of `indices` must be at least 2 and `indices.shape[-1] <= len(shape)`.
updates (Tensor): Define the source Tensor to be updated.
It has shape `indices.shape[:-1] + shape[indices.shape[-1]:]`.
shape (tuple[int]): Define the shape of the output tensor, has the same data type as indices.
The shape of `shape` is :math:`(x_1, x_2, ..., x_R)`, and the length of 'shape' is greater than
or equal to 2. In other words, the shape of `shape` is at least :math:`(x_1, x_2)`.
And the value of any element in `shape` must be greater than or equal to 1.
In other words, :math:`x_1 \ge 1`, :math:`x_2 \ge 1`.
`shape` can not be empty, and the elements in `shape` must be greater than or equal to 1.
Returns:
Tensor, the new tensor, has the same type as `update` and the same shape as `shape`.