  # numpy.sign () in Python

Arrays | NumPy | Python Methods and Functions

The numpy.sign (array [, out]) function is used to indicate the sign of a number element by element.
For integer inputs, if the array value is greater than 0, 1 is returned, if the array value is less than 0, -1 is returned, and if the array value is 0, 0.

Syntax: numpy.sign ()

Parameters:
array: [array_like] Input values.
out: [ndarray, optional] Output array placed with result.

Return: [ndarray] Returns the sign of array. If an array is scalar then the sign of array will be scalar.

Code 1:

` `

` # Python program illustrating # numpy.sign () method    # numpy import import numpy as geek     # input arrays array1 = [ 1 , 0 , - 13 ] array2 =   [ - 1 , 0 , 15 ]   # print input arrays print ( "input array1:" , array1) print ( "input array2: " , array2)    # define the sign of integers in the array print ( "Check sign of array1:" , geek.sign (array1)) print  ( "Check sign of array2:" , geek.sign (array2))  `

` `

Output:

` array1: [1, 0 , -13] array2: [-1, 0, 15] Check sign of array1: [1 0 -1] Check sign of array2: [-1 0 1] `

Code 2:

 ` # Python program illustrating ` ` # numpy.sign () method `   ` # numpy import ` ` import ` ` numpy as geek `   ` # define complex number sign ` ` print ` ` ( "Check sign of complex input1:" , geek.sign (` ` 7 ` ` - ` ` 3j ` `)) ` ` print ` ` (` ` "Check sign of complex input2:" ` `, geek.sign (` ` - ` ` 7 ` ` + ` ` 3j ` `) ) `

Output:

` Check sign of complex input1: (1 + 0j) Check sign of complex input2: (-1 + 0j) `