来自 numpy documentation on logarithms ,我找到了以 e 为底数取对数的函数, 2 , 和 10 :
import numpy as np
np.log(np.e**3) #3.0
np.log2(2**3) #3.0
np.log10(10**3) #3.0
但是,我如何在 numpy 中取以 n 为底的对数(例如 42)?
最佳答案
使用 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]
使用对数base change规则:
关于python - NumPy:以 n 为底的对数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25169297/