Open In App

numpy.sign() in Python

Last Updated : 03 Oct, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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 :




# Python Program illustrating
# numpy.sign() method
  
# importing numpy
import numpy as geek  
  
# input arrays    
array1 = [1, 0, -13]
array2 =  [-1, 0, 15]
  
# print the input arrays  
print ("input array1 : ", array1)
print ("input array2 : ", array2)
  
# determine the sign of integer numbers in an array  
print ("\nCheck sign of array1 : ", geek.sign(array1))
print ("\nCheck 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
  
# importing numpy  
import numpy as geek 
  
# determine the sign of complex number
print ("\n Check sign of complex input1 : ", geek.sign(7-3j))
print ("\n Check sign of complex input2 : ", geek.sign(-7 + 3j)) 


Output :

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

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


Similar Reads

Program to display Astrological sign or Zodiac sign for given date of birth
For given date of birth, this program displays an astrological sign or Zodiac sign.Examples : Input : Day = 10, Month = December Output : Sagittarius Explanation : People born on this date have a zodiac Sagittarius. Input : Day = 7, Month = September Output : Virgo Approach :Although the exact dates can shift plus or minus a day, depending on the y
8 min read
Python | Reverse sign of each element in given list
Given a list of integers, write a Python program to reverse the sign of each element in given list. Examples: Input : [-1, 2, 3, -4, 5, -6, -7] Output : [1, -2, -3, 4, -5, 6, 7] Input : [-5, 9, -23, -2, 7] Output : [5, -9, 23, 2, -7] Methods #1: List comprehension C/C++ Code # Python3 program to Convert positive # list integers to negative and vice
3 min read
Python | Counting sign change in list containing Positive and Negative Integers
Given a list containing Positive and Negative integers, We have to find number of times the sign(Positive or Negative) changes in the list. Input: [-1, 2, 3, -4, 5, -6, 7, 8, -9, 10, -11, 12] Output:9 Explanation : Sign change from -1 to 2, ans = 1 Sign change from 3 to -4, ans = 2 Sign change from -4 to 5, ans = 3 Sign change from 5 to -6, ans = 4
5 min read
Sign in Geeksforgeeks using Python Selenium
Project Description: Here, we're going to study a simple how-to log in GFG by selenium. Selenium is a free tool for automated trying out across exceptional browsers. then a simple requirement id and password. Requirements : Selenium - Selenium Python Introduction and Installation Steps to setup - First, go to the GeeksforGeeks website using this Li
1 min read
Python - Group Consecutive elements by Sign
Given a list group of consecutive elements on the basis of signs. Input : test_list = [5, -3, 2, 4, 6, -2, -1, -7, -9, 2, 3] Output : [[5], [-3], [2, 4, 6], [-2, -1, -7, -9], [2, 3]] Explanation : Elements inserted into new list on sign change.Input : test_list = [-2,3,4,5,6,-3] Output : [[-2], [3, 4, 5, 6], [-3]] Explanation : Elements inserted in
3 min read
Sign in Booking.com using Selenium in Python
In this article, we're going to study a simple how-to log in booking.com by selenium. Selenium is a free tool for automated trying out across exceptional browsers. Requirement: You need to install chromedriver and set path. Click here to download.Selenium is a powerful tool for controlling web browsers through programs and performing browser automa
2 min read
Python Program to get indices of sign change in a list
Given List, the task is to write a python program that extracts all the indices from which sign shift occurred. Input : test_list = [7, 6, -3, -4, -7, 8, 3, -6, 7, 8]Output : [1, 4, 6, 7]Explanation : 6 -> -3, at 1st index, -7 -> 8 at 4th index and so on are shifts. Input : test_list = [7, 6, -3, -4, -7, 8, 3, 6, 7, 8]Output : [1, 4]Explanati
6 min read
Compute the sign and natural logarithm of the determinant of an array in Python
In this article, we will cover how to compute the sign and natural logarithm of the determinant of an array in Python using NumPy. numpy.linalg.slogdet() method The numpy.linalg.slogdet() method provides us to compute the sign and natural logarithm of the determinant of an array in Python. A call to slogdet may overflow or underflow if the determin
3 min read
Django Sign Up and login with confirmation Email | Python
Django by default provides an authentication system configuration. User objects are the core of the authentication system. Today we will implement Django's authentication system. Modules required: Django install, crispy_forms Django Sign Up and Login with Confirmation EmailTo install crispy_forms you can use the terminal command: pip install --upgr
7 min read
Python | Numpy numpy.resize()
With the help of Numpy numpy.resize(), we can resize the size of an array. Array can be of any shape but to resize it we just need the size i.e (2, 2), (2, 3) and many more. During resizing numpy append zeros if values at a particular place is missing. Parameters: new_shape : [tuple of ints, or n ints] Shape of resized array refcheck : [bool, optio
2 min read
Article Tags :
Practice Tags :