You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mindspore.ops.Gather.rst 1.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. mindspore.ops.Gather
  2. ======================
  3. .. py:class:: mindspore.ops.Gather(*args, **kwargs)
  4. 返回输入Tensor在指定 `axis` 上 `input_indices` 索引对应的元素组成的切片。
  5. **输入:**
  6. - **input_params** (Tensor) - 原始Tensor,shape为 :math:`(x_1, x_2, ..., x_R)` 。
  7. - **input_indices** (Tensor) - 要切片的索引Tensor,shape为 :math:`(y_1, y_2, ..., y_S)` 。指定原始Tensor中要切片的索引。其值必须在 `[0, input_param.shape[axis])` 范围内,该校验仅在CPU上生效。在Ascend和GPU上超出该范围时,对应的值会置为0。数据类型可以是int32或int64。
  8. - **axis** (int) - 指定要切片的维度索引。
  9. **输出:**
  10. Tensor,shape为 :math:`input\_params.shape[:axis] + input\_indices.shape + input\_params.shape[axis + 1:]` 。
  11. **异常:**
  12. - **TypeError** - `axis` 不是int。
  13. - **TypeError** - `input_params` 或 `input_indices` 不是Tensor。
  14. **支持平台:**
  15. ``Ascend`` ``GPU`` ``CPU``
  16. **样例:**
  17. >>> input_params = Tensor(np.array([[1, 2, 7, 42], [3, 4, 54, 22], [2, 2, 55, 3]]), mindspore.float32)
  18. >>> input_indices = Tensor(np.array([1, 2]), mindspore.int32)
  19. >>> axis = 1
  20. >>> output = ops.Gather()(input_params, input_indices, axis)
  21. >>> print(output)
  22. [[ 2. 7.]
  23. [ 4. 54.]
  24. [ 2. 55.]]
  25. >>> axis = 0
  26. >>> output = ops.Gather()(input_params, input_indices, axis)
  27. >>> print(output)
  28. [[3. 4. 54. 22.]
  29. [2. 2. 55. 3.]]