【问题标题】:NumPy: Logarithm with base nNumPy:以 n 为底的对数
【发布时间】:2014-09-29 21:57:03
【问题描述】:

numpy documentation on logarithms,我找到了以e210 为底的对数的函数:

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)?

【问题讨论】:

    标签: python math numpy logarithm


    【解决方案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]
    

    其中使用对数base change规则:

    【讨论】:

    • 当我需要千数数组的对数时,我坚持使用 Numpy。
    • 我不明白为什么 base 不是 numpy 日志中的参数...我总是回到这里...
    猜你喜欢
    • 2018-10-24
    • 2016-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-16
    相关资源
    最近更新 更多