NumPy:以 n 为底的对数 [英] NumPy: Logarithm with base n

查看:20
本文介绍了NumPy:以 n 为底的对数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于对数的 numpy 文档,我有找到了对数取对数的函数 e210:

From the numpy documentation on logarithms, I have found functions to take the logarithm with base e, 2, and 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)?

However, how do I take the logarithm with base n (e.g. 42) in numpy?

推荐答案

使用 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]

使用对数基数变化规则:

这篇关于NumPy:以 n 为底的对数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆