python math模块

本文系转载,地址如下:

https://blog.csdn.net/iamaiearner/article/details/9381347

math模块实现了许多对浮点数的数学运算函数. 这些函数一般是对平台 C 库中同名函数的简单封装, 所以一般情况下, 不同平台下计算的结果可能稍微地有所不同, 有时候甚至有很大出入  

Python Math 函数  必须 import math
功能说明 指令 範例
返回 x 的反余弦 math.acos(x)
返回 x 的反双曲余弦 math.acosh(x)
返回 x 的反正弦 math.asin(x)
返回 x 的反双曲正弦 math.asinh(x)
返回 x 的反正切 math.atan(x)
返回 y/x 的反正切 math.atan2(y,x)
返回 x 的反双曲正切 math.atanh(x)
返回≧ x 的最小整數 math.ceil(x) math.floor(3.4) 結果 4
返回与 y 同号的 x 值 math.copysign(x,y)
返回 x 的余弦 math.cos(x)
返回 x 的双曲余弦 math.cosh(x)
將 x (弧长) 转成角度,与 radians 为反函数 math.degrees(x)
常数 e = 2.7128... math.e
返回 ex也就是 math.e**x math.exp(x)
返回 x 的绝对值 math.fabs(x)
返回 x! math.factorial(x)
返回 ≦ x 的最大整数 math.floor(x) math.floor(3.4) 結果 3
返回 x对y取模的余数
fmod 类似 %,但产生的结果可能与%不同,因为前者以y来决定余数的符号,后者你x来决定余数的符号。
math.fmod(x,y)
返回一個 2 元組 (2-tuple) 分別是假数 m (float)以及
一个指数 n(int),也就是 x = m×2与 ldexp 是反函数
math.frexp(x) math.frexp(1.625) 結果 (0.8125,1)
返回 x 阵列值的各項和 math.fsum(x) math.frexp([2,5]) 結果  7
返回  math.hypot(x,y)
如果 x = ±inf 也就是 ±∞
返回 True
math.isinf(x)
如果 x = Non (not a number)
返回 True
math.isnan(x)
返回 m×2n与 frexp 是反函数 math.ldexp(m,n)
返回 ,若不写a 內定 e math.log(x,a)
返回  math.log10(x)
返回  math.loglp(x)
返回 x 的小数部份与整数部份 math.modf(x)
返回常数 π (3.14159...) math.pi
返回 xy math.pow(x,y)
將 x(角度) 转成弧长,与 degrees 为反函数 math.radians(d)
返回 x 的正弦 math.sin(x)
返回 x 的双曲正弦 math.sinh(x)
返回  math.sqrt(x)
返回 x 的正切 math.tan(x)
返回 x 的双曲正切 math.tanh(x)
返回 x 的整数部份,等同 int math.trunc(x)
cmath模块包含了一些用于复数运算的函数. cmath模块的函数跟math模块函数基本一致,区别是cmath模块运算的是复数,math模块运算的是数学运算.
>>> cmath.sqrt(-1)
1j
>>> cmath.sqrt(9)
(3+0j)
>>> cmath.sin(1)
(0.8414709848078965+0j)
>>> cmath.log10(100)
(2+0j)

猜你喜欢

转载自blog.csdn.net/jn10010537/article/details/80375148