def sign(x, /, out=None, *, where=True, casting='same_kind',
order='K', dtype=None, subok=True, signature=None):
"""
Returns an element-wise indication of the sign of a number.
The `sign` function returns `-1 if x < 0`, `0 if x == 0`, `1 if x > 0`. For
complex inputs, this is a `element-wise` function.
Parameters
----------
x : array_like or scalar
Input array.
out : ndarray, None, or tuple of ndarray and None, optional
A location into which the result is stored. If not provided or `None`,
a freshly-allocated array is returned. If provided, it must have a
shape that the inputs broadcast to. If not provided or `None`, a
freshly-allocated array is returned. A tuple (possible only as a
keyword argument) must have length equal to the number of outputs.
where : array_like of bool, optional
Elements to include in the output, and their order. Only elements
corresponding to True in the `where` array are included in the
output. The output shape is identical to `x.shape`, except for
dimensions where `x` is scalar and `where` is broadcastable.
casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
Controls what kind of data casting may occur during the operation.
Defaults to 'same_kind'.
order : {'C', 'F', 'A'}, optional
Specify the order of the array. If order is 'C' (default), then the
array will be in C-contiguous order (last-index varies the
fastest). If order is 'F', then the returned array will
be in Fortran-contiguous order (first-index varies the
fastest). If order is 'A', then the returned array may
contain Fortran-ordered matrices with non-contiguous
regions. The default is 'K'.
dtype : str or dtype, optional
The dtype of the returned array. If not specified, the dtype of `a` is
used when `a` is an array, and float is used otherwise.
This argument can only be used to specify the return type when the
input parameter `out` is not used or is None.
subok : bool, optional
If True, then sub-classes will be passed-through, otherwise
the returned array will be forced to be a base-class array (default).
signature : callable, optional
A signature object that can be used in conjunction with `ufunc.outer` to
enable argument checking on ufunc operands. The signature can be
either a string or a call to the `numpy.typing` module's ``Signature``
class. See also the `ufuncs-overview` documentation.
Returns
-------
y : ndarray or scalar
The sign of `x`.
See Also
--------
numpy.signbit, numpy.copysign, numpy.frexp, numpy.ldexp
Examples
--------
>>> np.sign([1, 2, 3])
array([1, 1, 1])
>>> np.sign([-1, 0, 1.2])
array([-1., 0., 1.])
>>> np.sign(4-2j)
(1+0j)
"""
return _wrapfunc(x, 'sign', out=out, where=where,
signature=signature,
casting=casting, dtype=dtype, order=order)
In this code, numpy.sign() function is defined with several optional arguments such as out, where, casting, order, dtype, subok, and signature.
The sign() function is a straightforward routine, which returns an element-wise indication of the sign of a given number. If the input x is greater than zero, it returns 1, if it equals zero, returns 0, and if it is less than zero, it returns -1.