NumPy: Logarithm with base n

时间秒杀一切 提交于 2019-11-28 07:08:13
Banana

To get the logarithm with a custom base using math.log:

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

To get the logarithm with a custom base using 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]

As you would expect, note that the default case of np.log(np.e) == 1.0.


As a reminder, the logarithm base change rule is:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!