np.log 和math.log的底数是什么,默认都是e

np.log()

一直分不清楚log到底是以什么为底,就写下这个作为备忘

看到没,是以e为底的,如果是其他的就logn

import numpy as np
print( 'np.e:',np.e)
print( 'np.log([100,10000,10000]:',np.log([100,10000,10000]))   #输出结果是不是和你想象的不一样,请往下看   
print( 'np.log10([100,10000,10000]:',np.log10([100,10000,10000])) #以10为底的对数
print( 'np.log([1,np.e,np.e**2]):',np.log([1,np.e,np.e**2]))   #np.log(x) 默认底数为自然数e
print( 'np.log2([2,2**2,2**3]):',np.log2([2,2**2,2**3]))   #以2为底的对数
np.e: 2.718281828459045
np.log([100,10000,10000]: [4.60517019 9.21034037 9.21034037]
np.log10([100,10000,10000]: [2. 4. 4.]
np.log([1,np.e,np.e**2]): [0. 1. 2.]
np.log2([2,2**2,2**3]): [1. 2. 3.]

math.log()

但是,math的log又是怎么使用的,默认还是以e为底

import math 
#一般用法是math.log(a,底数),其中只输入一个值,则是以e为底
math.log(10)  #2.302585092994046
math.log(math.e)  #1.0
math.log(100,10)  #2.0
math.log(10,100)  #0.5
原文地址:https://www.cnblogs.com/cgmcoding/p/13640281.html