sign¶
- sign(x: array, /) array ¶
Returns an indication of the sign of a number for each element
x_i
of the input arrayx
.The sign function (also known as the signum function) of a number \(x_i\) is defined as
\[\begin{split}\operatorname{sign}(x_i) = \begin{cases} 0 & \textrm{if } x_i = 0 \\ \frac{x}{|x|} & \textrm{otherwise} \end{cases}\end{split}\]where \(|x_i|\) is the absolute value of \(x_i\).
- Parameters:
x (array) – input array. Should have a numeric data type.
- Returns:
out (array) – an array containing the evaluated result for each element in
x
. The returned array must have the same data type asx
.
Notes
Special cases
For real-valued operands,
If
x_i
is less than0
, the result is-1
.If
x_i
is either-0
or+0
, the result is0
.If
x_i
is greater than0
, the result is+1
.If
x_i
isNaN
, the result isNaN
.
For complex floating-point operands, let
a = real(x_i)
,b = imag(x_i)
, andIf
a
is either-0
or+0
andb
is either-0
or+0
, the result is0 + 0j
.If
a
isNaN
orb
isNaN
, the result isNaN + NaN j
.In the remaining cases, special cases must be handled according to the rules of complex number division (see
divide()
).
Changed in version 2022.12: Added complex data type support.