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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM