- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return an element-wise indication of the sign of complex types in Numpy
To return an element-wise indication of the sign of complex types, use the numpy.sign() method in Python Numpy.
The sign function returns -1 if x < 0, 0 if x==0, 1 if x > 0. nan is returned for nan inputs. For complex inputs, the sign function returns sign(x.real) + 0j if x.real != 0 else sign(x.imag) + 0j.
The complex(nan, 0) is returned for complex nan inputs. There is more than one definition of sign in common use for complex numbers. The definition used here is equivalent to x/x*x which is different from a common alternative, x/|x|.
Steps
At first, import the required library −
import numpy as np
Create an array with complex type using the array() method −
arr = np.array([56.+0.j, 27.+0.j, 68.-2.j, 49.+0.j, 120.-5.j,3 + 4.j])
Display the array −
print("Array...
", arr)
Get the type of the array −
print("
Our Array type...
", arr.dtype)
Get the dimensions of the Array −
print("
Our Array Dimension...
",arr.ndim)
Get the shape of the Array −
print("
Our Array Shape...
",arr.shape)
To return an element-wise indication of the sign of complex types, use the numpy.sign() method −
print("
Result...
",np.sign(arr))
Example
import numpy as np # Create an array with complex type using the array() method arr = np.array([56.+0.j, 27.+0.j, 68.-2.j, 49.+0.j, 120.-5.j,3 + 4.j]) # Display the array print("Array...
", arr) # Get the type of the array print("
Our Array type...
", arr.dtype) # Get the dimensions of the Array print("
Our Array Dimension...
",arr.ndim) # Get the shape of the Array print("
Our Array Shape...
",arr.shape) # To return an element-wise indication of the sign of complex types, use the numpy.sign() method in Python Numpy print("
Result...
",np.sign(arr))
Output
Array... [ 56.+0.j 27.+0.j 68.-2.j 49.+0.j 120.-5.j 3.+4.j] Our Array type... complex128 Our Array Dimension... 1 Our Array Shape... (6,) Result... [1.+0.j 1.+0.j 1.+0.j 1.+0.j 1.+0.j 1.+0.j]
- Related Articles
- Return an element-wise indication of the sign of a number in Numpy
- Return the element-wise square-root of a complex type array in Numpy
- Return the element-wise remainder of division in Numpy
- Return the reciprocal of the argument element-wise in Numpy
- Return the non-negative square-root of an array element-wise in Numpy
- Return the truth value of an array equal to another element-wise in Numpy
- Return the truth value of an array greater than another element-wise in Numpy
- Return the truth value of an array less than another element-wise in Numpy
- Change the sign of Numpy array values to that of a scalar element-wise
- Return the truth value of an array not equal to another element-wise in Numpy
- Compute the bit-wise NOT of an array element-wise in Numpy
- Return element-wise string multiple concatenation in Numpy
- Return the element-wise remainder of division with modulo operation in Numpy
- Return the element-wise remainder of division with fmod() operation in Numpy
- Return the base 10 logarithm of the input array element-wise in Numpy
