mindspore.ops.copysign

mindspore.ops.copysign(x, other)[source]

Create a new floating-point tensor with the magnitude of x and the sign of other, element-wise.

Parameters
  • x (Union[Tensor]) – Values to change the sign of.

  • other (Union[int, float, Tensor]) – The sign of other is copied to x. If x.shape != other.shape, other must be broadcastable to the shape of x (which is also the shape of the output).

Returns

Tensor. The dtype of the tensor is float. The values of x with the sign of other, the shape is the same as x.

Raises

TypeError – If dtype of the input is not in the given types or the input can not be converted to tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore.numpy as np
>>> from mindspore import ops
>>> x = np.array([[0.3, -0.7], [0.5, 0.5]])
>>> other = np.array([[-0.4, 0.6], [0.4, -0.6]])
>>> out = ops.copysign(x, other)
>>> print(out)
[[-0.3  0.7]
 [ 0.5 -0.5]]