NumPy:以n为底的对数


Answers:


135

要使用自定义底数获取对数,请使用math.log

import math
number = 74088  # = 42**3
base = 42
exponent = math.log(number, base)  # = 3

要使用自定义底数获取对数,请使用numpy.log

import numpy as np
array = np.array([74088, 3111696])  # = [42**3, 42**4]
base = 42
exponent = np.log(array) / np.log(base)  # = [3, 4]

如您所料,请注意默认情况下np.log(np.e) == 1.0


提醒一下,对数基数更改规则是:

\ log_b(x)= \ log_c(x)/ \ log_c(b)


37
当我需要一千个数字的对数时,我坚持使用Numpy。
Davidmh 2014年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.