python对数函数如何表示

待我称王封你为后i 2024-04-01 06:08 144阅读 0赞

095178da1d0b3bf956f7c1179ab5d1eb.jpeg

math.log(x) 就相当于数学中的ln(x),x>0,求底数为e的对数,e = 2.718281828459;math.log10(x) 就相当于数学中的lg(x),x>0,求底数为10的对数。可以通过log(x[, base])来设置底数,如 log(x, 10) 表示以10为底的对数。

语法

以下是 log() 方法的语法:

1

2

import math

math.log(x[, base])

注意:log()是不能直接访问的,需要导入 math 模块,通过静态对象调用该方法。

参数

x — 数值表达式。base — 可选,底数,默认为 e。

返回值

返回 x 的自然对数,x>0。

实例

以下展示了使用 log() 方法的实例:

1

2

3

4

5

6

7

8

#!/usr/bin/python

# -*- coding: UTF-8 -*-

import math # 导入 math 模块

print “math.log(100.12) : “, math.log(100.12)

print “math.log(100.72) : “, math.log(100.72)

print “math.log(119L) : “, math.log(119L)

print “math.log(math.pi) : “, math.log(math.pi)# 设置底数

print “math.log(10,2) : “, math.log(10,2)

以上实例运行后输出结果为:

1

2

3

4

5

math.log(100.12) : 4.60636946656

math.log(100.72) : 4.61234438974

math.log(119L) : 4.77912349311

math.log(math.pi) : 1.14472988585

math.log(10,2) : 3.32192809489

以上就是python中对数函数怎么表示的详细内容

转载自:微点阅读 https://www.weidianyuedu.com

发表评论

表情:
评论列表 (有 0 条评论,144人围观)

还没有评论,来说两句吧...

相关阅读

    相关 对数函数

    简介 一般地,对数函数是以[幂][Link 1]([真数][Link 2])为[自变量][Link 3],指数为[因变量][Link 4],底数为[常量][Link 5]