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.
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