From the numpy documentation on logarithms, I have found functions to take the logarithm with base e, 2, and 10:
import numpy as np
np.log(np.e**3) #3.0
np.log2(2**3) #3.0
np.log10(10**3) #3.0
However, how do I take the logarithm with base n (e.g. 42) in numpy?
To get the logarithm with a custom base using
math.log
:To get the logarithm with a custom base using
numpy.log
:As you would expect, note that the default case of
np.log(np.e) == 1.0
.As a reminder, the logarithm base change rule is: