对于:
x = log a b x=\log_{a}{b} x=logab
可以得到:
a x = b a^{x} =b ax=b
x ∗ l o g e a = l o g e b x *log_{e}{a} = log{_e}{b} x∗logea=logeb
即:
x = l o g e b l o g e a x = \frac{ log{_e}{b} }{ log_{e}{a} } x=logealogeb
使用方法
import numpy as np
def cus_log(x_value, base_x):
"""任意底数的log计算
:param x_value: x值
:param base_x: 底数
"""
return np.log(x_value) / np.log(base_x)
if __name__ == '__main__':
value_array = np.array([1, 2, 3, 4, 5])
print("以10为底:", np.log10(value_array))
print("以10为底:", cus_log(value_array, 10))
print("以33为底:", cus_log(value_array, 33))
得到结果:
以10为底: [0. 0.30103 0.47712125 0.60205999 0.69897 ]
以10为底: [0. 0.30103 0.47712125 0.60205999 0.69897 ]
以33为底: [0. 0.19823986 0.31420275 0.39647973 0.46029871]