Concept Flow - np.exp() and np.log()
Input array or value x
np.exp(x)
Calculate e^x
Output array or value
End
Start with input values, choose either exponential or natural log function, compute the result, and output the transformed values.
Jump into concepts and practice - no test required
import numpy as np x = np.array([1, 2, 3]) exp_x = np.exp(x) log_x = np.log(exp_x) print(exp_x) print(log_x)
| Step | Variable | Value | Operation | Result |
|---|---|---|---|---|
| 1 | x | [1 2 3] | Input array | [1 2 3] |
| 2 | exp_x | np.exp(x) | Calculate e^x element-wise | [2.71828183 7.3890561 20.08553692] |
| 3 | log_x | np.log(exp_x) | Calculate ln of exp_x element-wise | [1. 2. 3.] |
| 4 | print(exp_x) | - | Output exp_x | [2.71828183 7.3890561 20.08553692] |
| 5 | print(log_x) | - | Output log_x | [1. 2. 3.] |
| 6 | - | - | End of execution | All operations complete |
| Variable | Start | After np.exp() | After np.log() | Final |
|---|---|---|---|---|
| x | [1 2 3] | [1 2 3] | [1 2 3] | [1 2 3] |
| exp_x | N/A | [2.71828183 7.3890561 20.08553692] | [2.71828183 7.3890561 20.08553692] | [2.71828183 7.3890561 20.08553692] |
| log_x | N/A | N/A | [1. 2. 3.] | [1. 2. 3.] |
np.exp(x): computes e^x element-wise on arrays or scalars np.log(x): computes natural log (ln) element-wise, input must be positive np.log(np.exp(x)) returns x because log and exp are inverse functions Use np.exp() to scale values exponentially Use np.log() to transform data to logarithmic scale
np.exp(x) compute in NumPy?np.exp() calculates e (Euler's number, approximately 2.718) raised to the power of the input value.np.log(), square root is np.sqrt(), sine is np.sin().arr?np.log().np.exp() calculates exponentials, np.ln() does not exist, and np.log10() calculates base-10 logarithm.import numpy as np arr = np.array([1, 2, 3]) result = np.log(np.exp(arr)) print(result)
np.exp() to [1, 2, 3] gives [e^1, e^2, e^3] ≈ [2.718, 7.389, 20.086].import numpy as np arr = np.array([-1, 0, 1]) result = np.log(arr) print(result)
data. You want to normalize it by applying the natural logarithm, then reverse the transformation after some processing. Which sequence of operations correctly achieves this?np.log(data) transforms data to a logarithmic scale, useful for normalization.np.exp() to the logged data because exp is the inverse of log.np.exp(data) first, then np.log() on the result to reverse reverses the order incorrectly, Apply np.log10(data) first, then np.exp() on the result to reverse mixes log base 10 with exp (base e), Apply np.sqrt(data) first, then np.log() on the result to reverse uses sqrt which is unrelated.