首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >python常用标准库math:提供函数完成特殊的数学运算。

python常用标准库math:提供函数完成特殊的数学运算。

作者头像
用户7886150
修改2020-12-21 11:06:05
修改2020-12-21 11:06:05
9710
举报
文章被收录于专栏:bit哲学院bit哲学院

参考链接: Python中的数学math函数 2(对数和幂函数)

转载自品略图书馆 http://www.pinlue.com/article/2020/03/0118/169961870321.html 

math标准函数库概述 

math库一共提供了4个数学常数和44个函数。44个函数分为4类,包括:16个数值表示函数、8个幂对数函数、16个三角对数函数和四个高等特殊函数 

是Python提供内置数学类函数库 

在使用math库前,用import导入该库 

import math 

数学常数包括 

math.pi 数学常数π 

math.e 数学常数e 

math.tau 数学常数τ 

math.inf 浮点正无穷大 

math.nan 浮点“非数字”(NaN)值 

函数 

数论和表示函数 

math.ceil(x ) 

返回x的上限。 

math.ceil(4.01) 

math.floor(x ) 

返回x的最小值,小于或等于x的最大整数。 

math.floor(4.999) 

math.copysign(x,y ) 

若y<0,返回-1乘以x的绝对值;否则,返回x的绝对值 

math.copysign(2,-3) 

-2.0 

math.fabs(x ) 

返回x的绝对值。 

math.fabs(-3) 

math.factorial(x ) 

返回x阶乘。 

math.factorial(5) 

120 

math.fmod(x,y ) 

返回x%y(取余) 

math.fmod(20,7) 

6.0 

math.frexp(x ) 

返回一个元组(m,e),其计算方式为:x分别除0.5和1,得到一个值的范围 

math.frexp(10) 

(0.625, 4) 

math.fsum(可迭代的) 

对每个元素进行求和操作 

math.fsum((1,2,3,4)) 

10.0 

math.gcd(a,b ) 

返回整数a和b的最大公约数。 

`math.gcd(40,20) 

20 

math.isclose(a,b,*,rel_tol = 1e-09,abs_tol = 0.0 ) 

如果值a和b彼此接近则返回True, 否则返回False。 

math.isfinite(x ) 

如果x是正无穷大或负无穷大,则返回True,否则返回False 

math.isfinite(100) 

True 

math.isinf(x ) 

如果x是正无穷大或负无穷大,则返回True,否则返回False 

math.isinf(234) 

False 

math.isnan(x ) 

如果x不是数字True,否则返回False 

math.isnan(0.01) 

False 

math.ldexp(x,i ) 

返回x(2i)的值* 

math.ldexp(5,5) 

160.0 

math.modf(x ) 

返回由x的小数部分和整数部分组成的元组 

math.modf(12.34) 

(0.33999999999999986, 12.0) 

math.trunc(x ) 

返回x的整数部分 

math.trunc(6.789) 

math.trunc(math.pi) 

功率和对数函数 

math.exp(x ) 

返回ex。** 

math.exp(2) 

7.38905609893065 

math.expm1(x ) 

返回math.e的x(其值为2.71828)次方的值减1 

math.expm1(2) 

6.38905609893065 

math.log(x [,base ] ) 

使用一个参数,返回x的自然对数(到基数e)。 

math.log1p(x ) 

返回x+1的自然对数(基数为e)的值 

math.log1p(10) 

2.3978952727983707 

math.log2(x ) 

返回x的基2对数 

math.log2(20) 

4.321928094887363 

math.log10(x ) 

返回x的以10为底的对数 

math.log10(100) 

2.0 

math.pow(x,y ) 

返回x的y次方,即xy** 

math.pow(2,7) 

128.0 

math.sqrt(x ) 

返回x的平方根。 

math.sqrt(16) 

4.0 

三角函数 

math.acos(x ) 

以弧度为单位返回x的反余弦值。 

math.asin(x ) 

以弧度为单位返回x的反正弦值。 

math.atan(x ) 

以弧度为单位返回x的反正切值。 

math.atan2(y,x ) 

以弧度返回atan(y / x)。结果是在-pi和pi之间。 

math.cos(x ) 

返回x弧度的余弦值。 

math.hypot(x,y ) 

返回欧几里德范数,。 

math.sin(x ) 

返回x弧度的正弦值。 

math.tan(x ) 

返回x弧度的正切值。 

角度转换 

math.degrees(x ) 

将角度x从弧度转换为度数。 

math.degrees(math.pi) 

180.0 

math.radians(x ) 

将角度x从度数转换为弧度。 

math.radians(45) 

0.7853981633974483 

双曲函数 

math.acosh(x ) 

返回x的反双曲余弦值。 

math.asinh(x ) 

返回x的反双曲正弦值。 

math.atanh(x ) 

返回x的反双曲正切。 

math.cosh(x ) 

返回x的双曲余弦值。 

math.sinh(x ) 

返回x的双曲正弦值。 

math.tanh(x ) 

返回x的双曲正切值。 

特殊功能 

math.erf(x ) 

返回x处 的错误函数。 

math.erfc(x ) 

返回x处的互补误差函数。 

math.gamma(x ) 

在x处 返回Gamma函数。 

math.lgamma(x ) 

在返回Gamma函数的绝对值的自然对数X。

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档