copysign#

ivy.copysign(x1, x2, /, *, out=None)[source]#

Change the signs of x1 to match x2 x1 and x2 must be broadcastable to a common shape.

Parameters:
  • x1 (Union[Array, NativeArray, Number]) – Array or scalar to change the sign of

  • x2 (Union[Array, NativeArray, Number]) – Array or scalar from which the new signs are applied Unsigned zeroes are considered positive.

  • out (Optional[Union[Array, NativeArray]], default: None) – optional output array, for writing the result to.

Return type:

Array

Returns:

ret – x1 with the signs of x2. This is a scalar if both x1 and x2 are scalars.

Examples

>>> x1 = ivy.array([-1, 0, 23, 2])
>>> x2 = ivy.array([1, -1, -10, 44])
>>> ivy.copysign(x1, x2)
ivy.array([  1.,  -0., -23.,   2.])
>>> ivy.copysign(x1, -1)
ivy.array([ -1.,  -0., -23.,  -2.])
>>> ivy.copysign(-10, 1)
ivy.array(10.)
Array.copysign(self, x2, /, *, out=None)[source]#

ivy.Array instance method variant of ivy.copysign. This method simply wraps the function, and so the docstring for ivy.copysign also applies to this method with minimal changes.

Parameters:
  • x1 – Array or scalar to change the sign of

  • x2 (Union[Array, NativeArray, Number]) – Array or scalar from which the new signs are applied Unsigned zeroes are considered positive.

  • out (Optional[Array], default: None) – optional output array, for writing the result to.

Return type:

Array

Returns:

ret – x1 with the signs of x2. This is a scalar if both x1 and x2 are scalars.

Examples

>>> x1 = ivy.array([0, 1, 2, 3])
>>> x2 = ivy.array([-1, 1, -2, 2])
>>> x1.copysign(x2)
ivy.array([-0.,  1., -2.,  3.])
>>> x2.copysign(-1)
ivy.array([-1., -1., -2., -2.])
Container.copysign(self, x2, /, *, out=None)[source]#

ivy.Container instance method variant of ivy.copysign. This method simply wraps the function, and so the docstring for ivy.copysign also applies to this method with minimal changes.

Parameters:
  • self (Container) – Container to change the sign of

  • x2 (Container) – Container from which the new signs are applied Unsigned zeroes are considered positive.

  • out (Optional[Container], default: None) – optional output Container, for writing the result to.

Return type:

Container

Returns:

ret – x1 with the signs of x2. This is a scalar if both x1 and x2 are scalars.

Examples

>>> x1 = ivy.Container(a=ivy.array([0,1,2]), b=ivy.array(-1))
>>> x2 = ivy.Container(a=-1, b=ivy.array(10))
>>> x1.copysign(x2)
{
    a: ivy.array([-0., -1., -2.]),
    b: ivy.array(1.)
}
>>> x1.copysign(-1)
{
    a: ivy.array([-0., -1., -2.]),
    b: ivy.array(-1.)
}