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.AddN.rst 1.3 kB

4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. mindspore.ops.AddN
  2. ===================
  3. .. py:class:: mindspore.ops.AddN()
  4. 逐元素将所有输入的Tensor相加。
  5. 所有输入Tensor必须具有相同的shape。
  6. **输入:**
  7. - **x** (Union(tuple[Tensor], list[Tensor])) - Tensor组成的tuble或list,类型为 `bool_ <https://www.mindspore.cn/docs/api/zh-CN/master/api_python/mindspore.html#mindspore.dtype>`_ 或 `number <https://www.mindspore.cn/docs/api/zh-CN/master/api_python/mindspore.html#mindspore.dtype>`_ 。
  8. **输出:**
  9. Tensor,与 `x` 的每个Tensor具有相同的shape和数据类型。
  10. **异常:**
  11. - **TypeError** - `x` 既不是tuple,也不是list。
  12. - **ValueError** - `x` 中存在shape不同的Tensor。
  13. **支持平台:**
  14. ``Ascend`` ``GPU`` ``CPU``
  15. **样例:**
  16. >>> class NetAddN(nn.Cell):
  17. ... def __init__(self):
  18. ... super(NetAddN, self).__init__()
  19. ... self.addN = ops.AddN()
  20. ...
  21. ... def construct(self, *z):
  22. ... return self.addN(z)
  23. ...
  24. >>> net = NetAddN()
  25. >>> x = Tensor(np.array([1, 2, 3]), mindspore.float32)
  26. >>> y = Tensor(np.array([4, 5, 6]), mindspore.float32)
  27. >>> output = net(x, y, x, y)
  28. >>> print(output)
  29. [10. 14. 18.]