numpy.ldexp() in Python (original) (raw)
Last Updated : 22 Jul, 2021
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
import
numpy as geek
print
(geek.ldexp(
6
, geek.arange(
4
)))
print
(geek.ldexp(
-
8
, geek.arange(
4
)))
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
import
numpy as geek
print
(geek.ldexp(
-
5
+
9J
, geek.arange(
4
)))
Output:
TypeError: ufunc 'ldexp' not supported for the input types
Similar Reads
- numpy.index() in Python numpy.core.defchararray.index(arr, substring, start=0, end=None): Finds the lowest index of the sub-string in the specified range But if substring is not found, it raises ValueError. Parameters: arr : array-like or string to be searched. substring : substring to search for. start, end : [int, option 1 min read
- numpy.exp() in Python numpy.exp(array, out = None, where = True, casting = 'same_kind', order = 'K', dtype = None) : This mathematical function helps user to calculate exponential of all the elements in the input array. Parameters : array : [array_like]Input array or object whose elements, we need to test. out : [ndarray 4 min read
- numpy.find() in Python numpy.core.defchararray.find(arr, substring, start=0, end=None): Finds the lowest index of the sub-string in the specified range. Parameters: arr : array-like or string to be searched. substring : substring to search for. start, end : [int, optional] Range to search in. Returns : An integer array wi 1 min read
- numpy.expm1() in Python numpy.expm1(array, out = None, where = True, casting = 'same_kind', order = 'K', dtype = None) : This mathematical function helps user to calculate exponential of all the elements subtracting 1 from all the input array elements. Parameters : array : [array_like]Input array or object whose elements, 2 min read
- numpy.atleast_1d() in Python numpy.atleast_1d()function is used when we want to Convert inputs to arrays with at least one dimension. Scalar inputs are converted to 1-dimensional arrays, whilst higher-dimensional inputs are preserved. Syntax : numpy.atleast_1d(*arrays) Parameters : arrays1, arrays2, ... : [array_like] One or mo 2 min read
- numpy.mintypecode() function – Python numpy.mintypecode() function return the character for the minimum-size type to which given types can be safely cast. Syntax : numpy.mintypecode(typechars, typeset = 'GDFgdf', default = 'd') Parameters : typechars : [list of str or array_like] If a list of strings, each string should represent a dtyp 1 min read
- bin() in Python Python bin() function returns the binary string of a given integer. bin() function is used to convert integer to binary string. In this article, we will learn more about Python bin() function. Example In this example, we are using the bin() function to convert integer to binary string. C/C++ Code x 2 min read
- numpy.who function - Python numpy.who() function print the NumPy arrays in the given dictionary. Syntax : numpy.who(vardict = None) Parameters : vardict : [dict, optional] A dictionary possibly containing ndarrays. Return : Returns ‘None’. If there is no dictionary passed in or vardict is None then returns NumPy arrays in the 1 min read
- numpy.info() function in Python In Numpy we can get all the information about the function, class, or module like what will the parameter and what will be the type of the return value with the help of numpy.info() function. This function returns the help information for a function, class, or module. Syntax: numpy.info(numpy.info(o 1 min read
- numpy.dtype.kind() function – Python numpy.dtype.kind() function determine the character code by identifying the general kind of data. Syntax : numpy.dtype.kind(type) Parameters : type : [dtype] The input data-type. Return : Return the character code by identifying the general kind of data. Code #1 : # Python program explaining # numpy 1 min read