mindspore.numpy.copysign
- mindspore.numpy.copysign(x1, x2, dtype=None)[源代码]
Changes the sign of x1 to that of x2, element-wise.
If x2 is a scalar, its sign will be copied to all elements of x1.
Note
Numpy arguments out, where, casting, order, subok, signature, and extobj are not supported. Complex inputs are not supported now.
- Parameters
x1 (Union[int, float, list, tuple, Tensor]) – Values to change the sign of.
x2 (Union[int, float, list, tuple, Tensor]) – The sign of x2 is copied to x1. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).
dtype (
mindspore.dtype
, optional) – Defaults to None. Overrides the dtype of the output Tensor.
- Returns
Tensor or scalar. The values of x1 with the sign of x2. This is a scalar if both x1 and x2 are scalars.
- 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 >>> output = np.copysign(np.array([1, -1, -1]), np.array([-1, 1, -1])) >>> print(output) [-1 1 -1]