copysign(x1, x2, out=None, **kwargs)

Change 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.

  • x1 (ndarray or scalar) – Values to change the sign of.

  • x2 (ndarray or scalar) – The sign of x2 is copied to x1.

  • out (ndarray or None, optional) – A location into which the result is stored. It must be of the right shape and right type to hold the output. If not provided or None,a freshly-allocated array is returned.


  • out (ndarray or scalar) – The values of x1 with the sign of x2. This is a scalar if both x1 and x2 are scalars.

  • .. note:: – This function differs from the original numpy.copysign in the following aspects:

    • where param is not supported.


>>> np.copysign(1.3, -1)
>>> 1/np.copysign(0, 1)
>>> 1/np.copysign(0, -1)
>>> a = np.array([-1, 0, 1])
>>> np.copysign(a, -1.1)
array([-1., -0., -1.])
>>> np.copysign(a, np.arange(3)-1)
array([-1.,  0.,  1.])