文档反馈

问题文档片段

问题文档片段包含公式时,显示为空格。

提交类型
issue

有点复杂...

找人问问吧。

PR

小问题,全程线上修改...

一键搞定!

请选择提交类型

问题类型
规范和低错类

- 规范和低错类:

- 错别字或拼写错误,标点符号使用错误、公式错误或显示异常。

- 链接错误、空单元格、格式错误。

- 英文中包含中文字符。

- 界面和描述不一致,但不影响操作。

- 表述不通顺,但不影响理解。

- 版本号不匹配:如软件包名称、界面版本号。

易用性

- 易用性:

- 关键步骤错误或缺失,无法指导用户完成任务。

- 缺少主要功能描述、关键词解释、必要前提条件、注意事项等。

- 描述内容存在歧义指代不明、上下文矛盾。

- 逻辑不清晰,该分类、分项、分步骤的没有给出。

正确性

- 正确性:

- 技术原理、功能、支持平台、参数类型、异常报错等描述和软件实现不一致。

- 原理图、架构图等存在错误。

- 命令、命令参数等错误。

- 代码片段错误。

- 命令无法完成对应功能。

- 界面错误,无法指导操作。

- 代码样例运行报错、运行结果不符。

风险提示

- 风险提示:

- 对重要数据或系统存在风险的操作,缺少安全提示。

内容合规

- 内容合规:

- 违反法律法规,涉及政治、领土主权等敏感词。

- 内容侵权。

请选择问题类型

问题描述

点击输入详细问题描述,以帮助我们快速定位问题。

mindspore.Tensor.add

查看源文件
mindspore.Tensor.add(other)

selfother 逐元素相加。

outi=selfi+otheri

说明

  • selfother 具有不同的shape时,它们的shape必须要能广播为一个共同的shape。

  • selfother 不能同时为bool类型。[True, Tensor(True, bool_), Tensor(np.array([True]), bool_)]等都为bool类型。

  • selfother 遵循隐式类型转换规则,使数据类型保持一致。

  • self 的维度应大于或等于1。

参数:
  • other (Union[Tensor, number.Number, bool]) - other 是一个number.Number、bool值或数据类型为 numberbool_ 的Tensor。

返回:

Tensor,shape与输入 selfother 广播后的shape相同,数据类型为两个输入中精度较高的类型。

异常:
  • TypeError - other 不是Tensor、number.Number或bool。

支持平台:

Ascend GPU CPU

样例:

>>> import numpy as np
>>> import mindspore
>>> from mindspore import Tensor
>>> # case 1: x and y are both Tensor.
>>> x = Tensor(np.array([1, 2, 3]).astype(np.float32))
>>> y = Tensor(np.array([4, 5, 6]).astype(np.float32))
>>> output = Tensor.add(x, y)  # x.add(y)
>>> print(output)
[5. 7. 9.]
>>> # case 2: x is a scalar and y is a Tensor
>>> x = Tensor(1, mindspore.int32)
>>> y = Tensor(np.array([4, 5, 6]).astype(np.float32))
>>> output = Tensor.add(x, y)  # x.add(y)
>>> print(output)
[5. 6. 7.]
>>> # the data type of x is int32, the data type of y is float32,
>>> # and the output is the data format of higher precision float32.
>>> print(output.dtype)
Float32
mindspore.Tensor.add(other, *, alpha=1)

other 缩放后与 self 相加。

outi=selfi+alpha×otheri

说明

  • selfother 的shape不同时, 它们必须能够广播到一个共同的shape。

  • selfotheralpha 遵守隐式类型转换规则以使数据类型保持一致。

参数:
  • other (Union[Tensor, number.Number, bool]) - other 是一个 number.Number、一个 bool 或一个数据类型为 numberbool_ 的Tensor。

关键字参数:
  • alpha (number.Number) - 应用于 other 的缩放因子,默认值为 1

返回:

Tensor,其shape与 selfother 广播后的shape相同, 数据类型是 selfother 和 alpha 中精度更高或位数更多的类型。

异常:
  • TypeError - 如果 otheralpha 不是以下之一:Tensor、number.Number、bool。

  • TypeError - 如果 alpha 是 float 类型,但是 selfother 不是 float 类型。

  • TypeError - 如果 alpha 是 bool 类型,但是 selfother 不是 bool 类型。

支持平台:

Ascend GPU CPU

样例:

>>> import numpy as np
>>> import mindspore
>>> from mindspore import Tensor
>>> x = Tensor(1, mindspore.int32)
>>> y = Tensor(np.array([4, 5, 6]).astype(np.float32))
>>> alpha = 0.5
>>> output = Tensor.add(x, y, alpha=alpha)  # x.add(y, alpha=alpha)
>>> print(output)
[3. 3.5 4.]
>>> # the data type of x is int32, the data type of y is float32,
>>> # alpha is a float, and the output is the data format of higher precision float32.
>>> print(output.dtype)
Float32