np.log()与math.log()的区别与联系

您所在的位置:网站首页 log以十为底数 np.log()与math.log()的区别与联系

np.log()与math.log()的区别与联系

2023-09-04 09:28| 来源: 网络整理| 查看: 265

这两个包均提供了基础的以2,e,10为底求对数的情况,在这三种情况下两者的使用方式是一致的。 但是一般来讲,对于较复杂的log计算或者计算次数较多的时候,numpy计算速度的优势便体现了出来,所以要说明一下这两者在使用上的区别。

import math import numpy as np # 不写底数时默认以e为底 np.log(100) math.log(100) # 以2 e 10为底 print(np.log(100)) print(math.log(100)) print(np.log(np.e)) print(math.log(math.e)) print(np.log2(100)) print(math.log2(100)) print(np.log10(100)) print(math.log10(100)) # 任意底数 print(math.log(25, 5)) # 以5为底数 print(np.log(25)/ np.log(5)) #numpy在使用任意底数计算log的时候有点麻烦,需要log除法的公式转换一下 # 结果: # 4.605170185988092 # 4.605170185988092 # 1.0 # 1.0 # 6.643856189774724 # 6.643856189774724 # 2.0 # 2.0 # 2.0 # 2.0


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3