1 个回答
-
要使用自定义底数获取对数,请使用
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
。
提醒一下,对数基数更改规则是: