NumPy ufuncLesson 36Free preview
ufunc Logs
This lesson is part of NumPy · All levels
Summary
NumPy provides ufunc logarithms: np.log (base e), np.log2 (base 2), and np.log10 (base 10). The logarithm is only defined for positive numbers, so a zero or negative input will produce a warning and a value of NaN/-inf. np.log1p is useful for accurately calculating log(1+x) on very small x.
Key points
- It uses an exponential base (e), a base 2, a base 10.
- The input must be > 0; log(0) yields -inf and log yields negative NaN.
- Np.log1p(x) calculates log(1+x) high precision for small x.
- Logarithms are the element-wise operations on the entire array.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.