VOOZH about

URL: https://www.geeksforgeeks.org/python/numpy-sign-in-python/

⇱ numpy.sign() in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

numpy.sign() in Python

Last Updated : 3 Oct, 2019
numpy.sign(array [, out]) function is used to indicate the sign of a number element-wise. For integer inputs, if array value is greater than 0 it returns 1, if array value is less than 0 it returns -1, and if array value 0 it returns 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 : 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 :
Output :
 Check sign of complex input1 : (1+0j)

 Check sign of complex input2 : (-1+0j)
 
Comment
Article Tags:
Article Tags: