How do you do natural logs (e.g. “ln()”) with numpy in Python?

霸气de小男生 提交于 2019-12-09 04:27:44

问题


Using numpy, how can I do the following:

ln(x)

Is it equivalent to:

np.log(x)

I apologise for such a seemingly trivial question, but my understanding of the difference between log and ln is that ln is logspace e?


回答1:


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




回答2:


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




回答3:


I usually do like this:

from numpy import log as ln

Perhaps this can make you more comfortable.




回答4:


from numpy.lib.scimath import logn
from math import e

#using: x - var
logn(e, x)


来源:https://stackoverflow.com/questions/10593100/how-do-you-do-natural-logs-e-g-ln-with-numpy-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!