Trusted answers to developer questions

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

numpy.ldexp(x1, x2, /, out=None, *, where=True)

The syntax for the numpy.ldexp() function

The `numpy.ldexp()`

function takes the following parameter values.

: This represents the input array of multipliers and is a required parameter.**x1**

: This represents an array of two exponents and is a required parameter.**x2**

: This represents the location where the result is stored and is an optional parameter.**out**

: This is the condition over which the input is being broadcasted. At a given location where this condition is**where**`True`

, the resulting array will be set to the`ufunc`

result. Otherwise, the resulting array will retain its original value. This is an optional parameter.

: This represents other keyword arguments and is an optional parameter.****kwargs**

Let's view the code for this function.

import numpy as np # creating input arrays x1 = np.array([1, 2, 3, 4, 5]) x2 = np.array([2, 2, 2, 1, 1]) # implementing the ldexp() function myarray = np.ldexp(x1, x2) print(x1) print(x2) print("This is the ldexp values: ", myarray)

Implementing the ldexp() function

- Line 1: We import the
`numpy`

module. - Line 4: We create the input arrays
`x1`

and`x2`

using the`array()`

function. - Line 7: We implement the
`numpy.ldexp()`

function on the input arrays. We assign the result to a variable`myarray`

. - Line 9–10: We print the input arrays
`x1`

and`x2`

to the console. - Line 11: We print the variable
`myarray`

to the console.

Note: From the output, the first elements of`x1`

and`x2`

are`1`

and`2`

, that is:`x1 = 1`

`x2 = 2`

Therefore, from numpy.ldexp(x1, x2) = x1 ×$2^{x2}$ , numpy.ldexp (1, 2) = 1 ×$2^{2} = 4$ .

RELATED TAGS

function

numpy

python

communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Related Courses