mindspore/docs/api/api_python/ops/mindspore.ops.AddN.rst

43 lines
1.2 KiB
ReStructuredText
Raw Normal View History

2021-12-04 13:55:42 +08:00
mindspore.ops.AddN
===================
2021-12-22 11:46:09 +08:00
.. py:class:: mindspore.ops.AddN()
2021-12-04 13:55:42 +08:00
2021-12-22 11:46:09 +08:00
逐元素将所有输入的Tensor相加。
2021-12-04 13:55:42 +08:00
所有输入Tensor必须具有相同的shape。
**输入:**
2021-12-22 11:46:09 +08:00
- **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>`_
2021-12-04 13:55:42 +08:00
**输出:**
Tensor`x` 的每个Tensor具有相同的shape和数据类型。
**异常:**
- **TypeError** - `x` 既不是tuple也不是list。
2021-12-22 11:46:09 +08:00
- **ValueError** - `x` 中存在shape不同的Tensor。
2021-12-04 13:55:42 +08:00
**支持平台:**
2021-12-04 20:36:47 +08:00
2021-12-04 13:55:42 +08:00
``Ascend`` ``GPU`` ``CPU``
**样例:**
>>> class NetAddN(nn.Cell):
... def __init__(self):
... super(NetAddN, self).__init__()
... self.addN = ops.AddN()
...
... def construct(self, *z):
... return self.addN(z)
...
>>> net = NetAddN()
>>> x = Tensor(np.array([1, 2, 3]), mindspore.float32)
>>> y = Tensor(np.array([4, 5, 6]), mindspore.float32)
>>> output = net(x, y, x, y)
>>> print(output)
[10. 14. 18.]