# Return mantissa and exponent as a pair of a given list in Numpy

NumpyServer Side ProgrammingProgramming

To return mantissa and exponent as a pair of a given list, 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.

The condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.

## Steps

At first, import the required library −

import numpy as np

Create a list −

myList = [15.9, 39.2, 166.8, -14.8, 78,6, -19.8]


Display the array −

print("List...\n", myList)

Length of the list −

print("\nList length...\n", len(myList))


Type of the list −

print("\nList type...\n", type(myList))

To return mantissa and exponent as a pair of a given list, use the numpy.frexp() method in Python Numpy −

print("\nResult...\n",np.frexp(myList))


## Example

import numpy as np

# Create a list
myList = [15.9, 39.2, 166.8, -14.8, 78,6, -19.8]

# Display the list
print("List...\n", myList)

# Length of the list
print("\nList length...\n", len(myList))

# Type of the list
print("\nList type...\n", type(myList))

# To return mantissa and exponent as a pair of a given list, use the numpy.frexp() method in Python Numpy
print("\nResult...\n",np.frexp(myList))

## Output

List...
[15.9, 39.2, 166.8, -14.8, 78, 6, -19.8]

List length...
7

List type...
<class 'list'>

Result...
(array([ 0.99375 , 0.6125 , 0.6515625, -0.925 , 0.609375 , 0.75 , -0.61875 ]), array([4, 6, 8, 4, 7, 3, 5], dtype=int32))
Updated on 08-Feb-2022 07:05:53