0
0
NumPydata~5 mins

np.exp() and np.log() in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the function np.exp() do in numpy?

np.exp() calculates the exponential of all elements in the input array. It raises the mathematical constant e (about 2.718) to the power of each element.

Click to reveal answer
beginner
What is the purpose of np.log() in numpy?

np.log() computes the natural logarithm (log base e) of each element in the input array. It is the inverse operation of np.exp().

Click to reveal answer
beginner
If x = np.array([1, 2, 3]), what is the output of np.exp(x)?

The output is an array where each element is e raised to the power of the corresponding element in x:

[e^1, e^2, e^3][2.718, 7.389, 20.086]

Click to reveal answer
intermediate
What happens if you apply np.log() to an array containing zero or negative numbers?

Applying np.log() to zero or negative numbers results in -inf or nan values and usually raises a warning, because the natural logarithm is not defined for those values.

Click to reveal answer
intermediate
How are np.exp() and np.log() related mathematically?

np.exp() and np.log() are inverse functions. This means np.exp(np.log(x)) = x for positive x, and np.log(np.exp(x)) = x for any real x.

Click to reveal answer
What does np.exp(0) return?
A0
Be
C1
DUndefined
Which numpy function would you use to find the natural logarithm of an array?
Anp.log()
Bnp.power()
Cnp.sqrt()
Dnp.exp()
What is the result of np.log(np.exp(3))?
A0
Be^3
CUndefined
D3
What will np.log(-1) return?
Anan or warning
BA real number
C0
D1
If arr = np.array([1, 2, 3]), what does np.exp(arr) compute?
ANatural logarithm of each element
Be raised to the power of each element
CSquare of each element
DSum of elements
Explain in your own words what np.exp() and np.log() do and how they are related.
Think about how one function can undo the effect of the other.
You got /3 concepts.
    Describe what happens if you try to take the natural logarithm of zero or a negative number using np.log().
    Consider the domain of the logarithm function.
    You got /3 concepts.