How do you do natural logs (e.g. "ln()") with numpy in Python?
np.log
is ln
, whereas np.log10
is your standard base 10 log.
Relevant documentation:
http://docs.scipy.org/doc/numpy/reference/generated/numpy.log.html
http://docs.scipy.org/doc/numpy/reference/generated/numpy.log10.html
Correct, np.log(x)
is the Natural Log (base e
log) of x
.
For other bases, remember this law of logs: log-b(x) = log-k(x) / log-k(b)
where log-b
is the log in some arbitrary base b
, and log-k
is the log in base k
, e.g.
here k = e
l = np.log(x) / np.log(100)
and l
is the log-base-100 of x
I usually do like this:
from numpy import log as ln
Perhaps this can make you more comfortable.