Challenge - 5 Problems
Exponential and Logarithm Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of np.exp() on a numpy array
What is the output of the following code?
NumPy
import numpy as np arr = np.array([0, 1, 2]) result = np.exp(arr) print(result)
Attempts:
2 left
💡 Hint
Recall that np.exp(x) calculates e to the power of x for each element.
✗ Incorrect
np.exp() calculates the exponential of each element. e^0=1, e^1≈2.718, e^2≈7.389.
❓ Predict Output
intermediate2:00remaining
Output of np.log() on a numpy array
What is the output of this code snippet?
NumPy
import numpy as np arr = np.array([1, np.e, np.e**2]) result = np.log(arr) print(result)
Attempts:
2 left
💡 Hint
np.log() returns the natural logarithm (base e) of each element.
✗ Incorrect
Since log(e^x) = x, the output is [0, 1, 2].
❓ data_output
advanced2:00remaining
Result of combining np.exp() and np.log()
What is the output of this code?
NumPy
import numpy as np arr = np.array([1, 2, 3]) result = np.exp(np.log(arr)) print(result)
Attempts:
2 left
💡 Hint
Think about what happens when you apply exp to the log of a number.
✗ Incorrect
np.exp(np.log(x)) returns x for positive x, so the output matches the original array.
🧠 Conceptual
advanced2:00remaining
Behavior of np.log() with zero and negative inputs
What happens when you run np.log() on an array containing zero or negative numbers?
NumPy
import numpy as np arr = np.array([0, -1, 1]) result = np.log(arr) print(result)
Attempts:
2 left
💡 Hint
Logarithm of zero or negative numbers is not defined in real numbers.
✗ Incorrect
np.log(0) returns -inf, np.log(negative) returns nan, and a runtime warning is issued.
🚀 Application
expert3:00remaining
Calculate the geometric mean using np.log() and np.exp()
Given a numpy array of positive numbers, which code correctly calculates the geometric mean?
NumPy
import numpy as np arr = np.array([1, 10, 100])
Attempts:
2 left
💡 Hint
Geometric mean is the nth root of the product of n numbers, which can be calculated using logs and exponentials.
✗ Incorrect
Taking the log of numbers, averaging, then exponentiating gives the geometric mean.