在Python中如何用numpy处理自然日志(例如“ ln()”)?

问题:在Python中如何用numpy处理自然日志(例如“ ln()”)?

使用numpy,如何执行以下操作:

ln(x)

它等效于:

np.log(x)

我这样一个看似微不足道的问题道歉,但我之间的差异的理解logln被认为ln是LOGSPACEè?

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?


回答 0


回答 1

正确,np.log(x)是的自然日志(基本e日志)x

对于其他基准,请记住该日志定律:log-b(x) = log-k(x) / log-k(b)log-b任意任意基准中b,log是哪里,log-k在基准中是log k,例如

这里k = e

l = np.log(x) / np.log(100)

并且l是x的log-base-100

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


回答 2

我通常这样做:

from numpy import log as ln

也许这可以使您更舒适。

I usually do like this:

from numpy import log as ln

Perhaps this can make you more comfortable.


回答 3

您可以简单地通过将日志的底数设为e来进行相反的操作。

import math

e = 2.718281

math.log(e, 10) = 2.302585093
ln(10) = 2.30258093

You could simple just do the reverse by making the base of log to e.

import math

e = 2.718281

math.log(e, 10) = 2.302585093
ln(10) = 2.30258093

回答 4

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

#using: x - var
logn(e, x)
from numpy.lib.scimath import logn
from math import e

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