copysign¶
- copysign(x1: array | int | float, x2: array | int | float, /) array¶
Composes a floating-point value with the magnitude of
x1_iand the sign ofx2_ifor each element of the input arrayx1.- Parameters:
x1 (Union[array, int, float]) – input array containing magnitudes. Should have a real-valued floating-point data type.
x2 (Union[array, int, float]) – input array whose sign bits are applied to the magnitudes of
x1. Must be compatible withx1(see Broadcasting). Should have a real-valued floating-point data type.
- Returns:
out (array) – an array containing the element-wise results. The returned array must have a floating-point data type determined by Type Promotion Rules.
Notes
At least one of
x1orx2must be an array.
Special cases
For real-valued floating-point operands, let
|x|be the absolute value, and ifx1_iis notNaN,If
x2_iis less than0, the result is-|x1_i|.If
x2_iis-0, the result is-|x1_i|.If
x2_iis+0, the result is|x1_i|.If
x2_iis greater than0, the result is|x1_i|.If
x2_iisNaNand the sign bit ofx2_iis1, the result is-|x1_i|.If
x2_iisNaNand the sign bit ofx2_iis0, the result is|x1_i|.If
x1_iisNaNandx2_iis less than0, the result isNaNwith a sign bit of1.If
x1_iisNaNandx2_iis-0, the result isNaNwith a sign bit of1.If
x1_iisNaNandx2_iis+0, the result isNaNwith a sign bit of0.If
x1_iisNaNandx2_iis greater than0, the result isNaNwith a sign bit of0.If
x1_iisNaNandx2_iisNaNand the sign bit ofx2_iis1, the result isNaNwith a sign bit of1.If
x1_iisNaNandx2_iisNaNand the sign bit ofx2_iis0, the result isNaNwith a sign bit of0.
New in version 2023.12.
Changed in version 2024.12: Added scalar argument support.