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

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

问题描述

关于对数的numpy文档中,找到以底数 e 为底的对数的函数 2 10 :

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?

推荐答案

使用使用 numpy.log来获取具有自定义基数的对数:

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]

请注意,默认情况下为np.log(np.e) == 1.0.

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:

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

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