copysign¶
- copysign(x1: array | int | float, x2: array | int | float, /) array ¶
Composes a floating-point value with the magnitude of
x1_i
and the sign ofx2_i
for 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
x1
orx2
must be an array.
Special cases
For real-valued floating-point operands, let
|x|
be the absolute value, and ifx1_i
is notNaN
,If
x2_i
is less than0
, the result is-|x1_i|
.If
x2_i
is-0
, the result is-|x1_i|
.If
x2_i
is+0
, the result is|x1_i|
.If
x2_i
is greater than0
, the result is|x1_i|
.If
x2_i
isNaN
and the sign bit ofx2_i
is1
, the result is-|x1_i|
.If
x2_i
isNaN
and the sign bit ofx2_i
is0
, the result is|x1_i|
.If
x1_i
isNaN
andx2_i
is less than0
, the result isNaN
with a sign bit of1
.If
x1_i
isNaN
andx2_i
is-0
, the result isNaN
with a sign bit of1
.If
x1_i
isNaN
andx2_i
is+0
, the result isNaN
with a sign bit of0
.If
x1_i
isNaN
andx2_i
is greater than0
, the result isNaN
with a sign bit of0
.If
x1_i
isNaN
andx2_i
isNaN
and the sign bit ofx2_i
is1
, the result isNaN
with a sign bit of1
.If
x1_i
isNaN
andx2_i
isNaN
and the sign bit ofx2_i
is0
, the result isNaN
with a sign bit of0
.
New in version 2023.12.