HomeLanguagesnumpy.ldexp() in Python

numpy.ldexp() in Python

In Python, numpy.ldexp(arr1, arr2[, out]) function returns arr1 * (2**arr2), element-wise. This is also called as inverse of numpy.frexp() function. 

Syntax: numpy.ldexp()
Parameters: 
arr1: [array_like] Array of multipliers. 
arr2: [array_like, int] Array of twos exponents. 
out: [ndarray, optional] Output array for the result.
Returns: [ndarray, scalar] Return the result of arr1 * (2**arr2). This is a scalar if both arr1 and arr2 are scalars. 
 

Code #1:  

Python3




# Python program explaining
# numpy.ldexp() method
 
# importing numpy 
import numpy as geek
 
# ldexp() Function on + ve nd -ve Numbers
print(geek.ldexp(6, geek.arange(4)))
print(geek.ldexp(-8, geek.arange(4)))
 
# ldexp() Function on fractional Number
print(geek.ldexp(5.2, geek.arange(3)))
print(geek.ldexp(-3.2, geek.arange(3)))


Output: 

[  6.  12.  24.  48.]
[ -8. -16. -32. -64.]
[  5.2  10.4  20.8]
[ -3.2  -6.4 -12.8]

 

Code #2: Complex data-types are not supported, they will raise a TypeError.  

Python3




# Python program explaining
# numpy.ldexp() method
 
# importing numpy
import numpy as geek
 
# ldexp() Function on complex dtypes
print(geek.ldexp(-5 + 9J, geek.arange(4)))


Output: 

 TypeError: ufunc 'ldexp' not supported for the input types

 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32548 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6922 POSTS0 COMMENTS
Nicole Veronica
12039 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12145 POSTS0 COMMENTS
Shaida Kate Naidoo
7059 POSTS0 COMMENTS
Ted Musemwa
7300 POSTS0 COMMENTS
Thapelo Manthata
7016 POSTS0 COMMENTS
Umr Jansen
7005 POSTS0 COMMENTS