- 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 mantissa and exponent as a pair of a given tuple in Numpy
To return mantissa and exponent as a pair of a given tuple, use the numpy.frexp() method in Python Numpy. The out is a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.
NumPy offers comprehensive mathematical functions, random number generators, linear algebra routines, Fourier transforms, and more. It supports a wide range of hardware and computing platforms, and plays well with distributed, GPU, and sparse array libraries.
Steps
At first, import the required library −
import numpy as np
Create a tuple −
myTuple = (37.2, 39.2, 166.8, -14.8, 78,6, -19.8)
Display the array −
print("Tuple...
", myTuple)
Length of the tuple −
print("
Tuple length...
", len(myTuple))
Type of the tuple −
print("
Tuple type...
", type(myTuple))
To return mantissa and exponent as a pair of a given tuple, use the numpy.frexp() method in Python Numpy −
print("
Result...
",np.frexp(myTuple))
Example
import numpy as np # Create a tuple myTuple = (37.2, 39.2, 166.8, -14.8, 78,6, -19.8) # Display the tuple print("Tuple...
", myTuple) # Length of the tuple print("
Tuple length...
", len(myTuple)) # Type of the tuple print("
Tuple type...
", type(myTuple)) # To return mantissa and exponent as a pair of a given tuple, use the numpy.frexp() method in Python Numpy print("
Result...
",np.frexp(myTuple))
Output
Tuple... (37.2, 39.2, 166.8, -14.8, 78, 6, -19.8) Tuple length... 7 Tuple type... <class 'tuple'> Result... (array([ 0.58125 , 0.6125 , 0.6515625, -0.925 , 0.609375 , 0.75 , -0.61875 ]), array([6, 6, 8, 4, 7, 3, 5], dtype=int32))