mindspore.ops.copysign

查看源文件
mindspore.ops.copysign(x, other)[源代码]

创建一个float tensor,由 x 的绝对值和 other 的符号组成。

支持广播。

参数:
  • x (Union[Tensor]) - 输入tensor

  • other (Union[int, float, Tensor]) - 决定返回值符号的tensor。

返回:

Tensor

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> # case 1: When other is a tensor
>>> x = mindspore.tensor([[0.3, -0.7],
...                       [0.5, 0.5]])
>>> other = mindspore.tensor([-0.4, 0.6])
>>> output = mindspore.ops.copysign(x, other)
>>> print(output)
[[-0.3  0.7]
 [-0.5  0.5]]
>>> # case 2: When other is a scalar
>>> output = mindspore.ops.copysign(x, 2)
>>> print(output)
[[0.3 0.7]
 [0.5 0.5]]