sign(x, out=None, **kwargs)

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. Only supports real number.

  • x (ndarray or a scalar) – Input values.

  • out (ndarray or None, optional) – A location into which the result is stored. If provided, it must have the same shape and dtype as input ndarray. If not provided or None, a freshly-allocated array is returned.


  • y (ndarray) – The sign of x. This is a scalar if x is a scalar.

  • .. note::

    • Only supports real number as input elements.

    • Input type does not support Python native iterables(list, tuple, …).

    • out param: cannot perform auto broadcasting. out ndarray’s shape must be the same as the expected output.

    • out param: cannot perform auto type cast. out ndarray’s dtype must be the same as the expected output.

    • out param does not support scalar input case.


>>> a = np.array([-5., 4.5])
>>> np.sign(a)
array([-1.,  1.])
Scalars as input:
>>> np.sign(4.0)
>>> np.sign(0)
Use ``out`` parameter:
>>> b = np.zeros((2, ))
>>> np.sign(a, out=b)
array([-1.,  1.])
>>> b
array([-1.,  1.])