ceil(x)

返回整数

>>> math.ceil(-1.273)
-1
>>> math.ceil(1.33)
2

copysign(x,y)

把y的符号给x,y可以是0

>>> math.copysign(12, -0.0)
-12.0
>>> math.copysign(-27, 29)
27.0

fabs(x)

返回绝对值

>>> math.fabs(-12)
12.0
>>> math.fabs(12)
12.0

factorial(x)

返回阶乘的数

>>> math.factorial(3)
6
>>> math.factorial(4)
24

floor(x)

取整数

>>> math.floor(1.23)
1
>>> math.floor(1.6)
1

fmod(x,y)

返回余数

>>> math.fmod(12,3)
0.0
>>> math.fmod(2,3)
2.0

frexp(x)

返回一个(m,e)的元组,其中x=m*2**e,0.5<=abs(m)<1

>>> math.frexp(5)
(0.625, 3)
>>> math.frexp(124)
(0.96875, 7)

fsum(iterable)

对迭代器里面的所有元素进行求和

>>> math.fsum([1.2, 3.4, 2.5])
7.1
>>> math.fsum((i for i in range(10)))
45.0

gcd(x,y)

求x和y的最大公约数

>>> math.gcd(15,10)
5
>>> math.gcd(100,25)
25

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

判断x和y的值是否相近,rel_tol是最大绝对值,abs_tol是最小绝对值

>>> math.isclose(12, 12.3, rel_tol = 2, abs_tol = 1)
True
>>> math.isclose(1, 2.3, rel_tol = 3, abs_tol = 1)
True

isfinite(x)

判断是否为无穷大或负无穷大,如果不是则返回True

>>> math.isfinite(3)
True

isinf(x)

判断是否为无穷大或负无穷大,如果是则返回True

>>> math.isinf(2)
False

isnan(x)

如果不是数字,返回True;如果是数字,返回False

>>> math.isnan(2)
False

ldexp(x,i)

返回x*(2**i)

>>> math.ldexp(2,1)
4.0
>>> math.ldexp(3,3)
24.0

modf(x)

返回一个(a,b)的元组,a是x的小数部分,b是x的整数部分

>>> math.modf(2.13)
(0.1299999999999999, 2.0)
>>> math.modf(3)
(0.0, 3.0)
>>> math.modf(1.2)
(0.19999999999999996, 1.0)

trunc(x)

返回整数部分

>>> math.trunc(1.23)
1
>>> math.trunc(0.123)
0

exp(x)

相当于math.e**x,不过更加精确

>>> math.exp(2)
7.38905609893065
>>> math.exp(1)
2.718281828459045

expml(x)

相当于exp(x)-1,不过更加精确

>>> math.exp(1e-5)-1
1.0000050000069649e-05
>>> math.expm1(1e-5)
1.0000050000166667e-05

log(x[, base])

取对数,base默认是常数e

>>> math.log(4, 2)
2.0
>>> math.log(math.e)
1.0

loglp(x)

取以math.e为底x+1的对数

>>> math.log1p(math.e-1)  ##其中是数字"1",不是字母"l"
1.0

log2(x)

相当于log(x,2)不过更加精确

>>> math.log2(3)
1.584962500721156
>>> math.log(3,2)
1.5849625007211563

log10(x)

相当于log(x,2)不过更加精确

>>> math.log10(10)
1.0
>>> math.log10(100)
2.0

pow(x,y)

返回x的y次幂

>>> math.pow(2, 4)
16.0

sqrt(x)

开平方根

>>> math.sqrt(4)
2.0
>>> math.sqrt(16)
4.0

acos(x)

反cos函数

>>> math.acos(0.5)
1.0471975511965979
>>> math.pi/3
1.0471975511965976

asin(x)

反sin函数

>>> math.asin(0.5)
0.5235987755982989
>>> math.pi/6
0.5235987755982988

atan(x)

反tan函数

>>> math.atan(1)
0.7853981633974483
>>> math.pi/4
0.7853981633974483

atan2(y,x)

矢量(x,y)与x的夹角,即tan(y/x)的大小

>>> math.atan2(1,1)
0.7853981633974483
>>> math.pi/4
0.7853981633974483

cos(x)

>>> math.cos(0)
1.0
>>> math.cos(math.pi/3)
0.5000000000000001

hypot(x,y)

(x,y)到原点的距离

>>> math.hypot(3,4)
5.0
>>> math.hypot(5,12)
13.0

sin(x)

>>> math.sin(math.pi/2)
1.0
>>> math.sin(math.pi/6)
0.49999999999999994

tan(x)

>>> math.tan(0)
0.0
>>> math.tan(math.pi/4)
0.9999999999999999

degrees(x)

把弧度转换为角度

>>> math.degrees(math.pi/2)
90.0
>>> math.degrees(math.pi/3)
59.99999999999999

radians(x)

把角度转换为弧度

>>> math.radians(90)
1.5707963267948966
>>> math.radians(30)
0.5235987755982988

三角函数双曲线

acosh(x)
asinh(x)
atanh(x)
cosh(x)
sinh(x)
tanh(x

erf(x)

\[\varPhi \left( x \right) =\frac{1}{\sqrt{2\pi}}\int_{-\infty}^x{e^{\frac{-t^2}{2}}}dt
\]

>>> math.erf(100)
1.0
>>> math.erf(100000)
1.0
>>> math.erf(0.123)
0.1380938816903886

erfc(x)

等同于1.0-erf(x)

>>> math.erf(0.5)
0.5204998778130465
>>> math.erfc(0.5)
0.4795001221869534
>>> math.erf(0.5)+math.erfc(0.5)
1.0

gamma(x)

\[\varGamma \left( x \right) =\int_0^{+\infty}{t^{x-1}e^{-t}dt}
\]

>>> math.gamma(100)
9.332621544394415e+155
>>> math.gamma(45)
2.658271574788449e+54

lgamma(x)

gamma函数的以常数e为底对数

>>> math.lgamma(100)
359.1342053695754
>>> math.lgamma(666)
3661.5273394029496

pi

e

tau

等同于2*pi

inf

无穷大

nan

等同于“not a number”

Python的math模块的更多相关文章

  1. python之math模块

    1.math简介 >>>import math #导入math模块 >>>dir(math) #这句可查看所有函数名列表 >>>help(math ...

  2. python 的math模块

    数学模块用法:import math# 或 from math import * 变量 描述 math.e 自然对数的底e math.pi 圆周率pi 函数名 描述 math.ceil(x) 对x向上 ...

  3. python 之math模块

    一.math 简介 import math # 导入模块 ret = dir(math) # 查看所有函数名列表 print(ret) # ['__doc__', '__loader__', '__n ...

  4. python中math模块常用的方法整理

    ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回x copysign:把y的正负号加到x前面,可以使用0 cos:求x的余弦,x必须是弧度 degrees:把x从弧度转换成角度 e:表示 ...

  5. (转)python中math模块常用的方法整理

    原文:https://www.cnblogs.com/renpingsheng/p/7171950.html#ceil ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回x copysig ...

  6. 【转载】python中math模块常用的方法

    转自:https://www.cnblogs.com/renpingsheng/p/7171950.html ceil #取大于等于x的最小的整数值,如果x是一个整数,则返回x ceil(x) Ret ...

  7. Python:python中math模块中提供的基本数学函数

    sin(x):求x的正弦 cos(x):求x的余弦 asin(x):求x的反正弦 acos(x):求x的反余弦 tan(x):求x的正切 atan(x):求x的反正切 hypot(x,y):求直角三角 ...

  8. Python:基本运算、基本函数(包括复数)、Math模块、NumPy模块

    基本运算 x**2 : x^2 若x是mat矩阵,那就表示x内每个元素求平方 inf:表示正无穷 逻辑运算符:and,or,not 字典的get方法 a.get(k,d) 1 1 get相当于一条if ...

  9. Python常用的一些内建函数和math模块函数

    一:Python内建函数 # abs取绝对值 num = -10 print(abs(num)) # max 求最大值 print(max(6, 9, 2, 12, 8)) # min求最小值 pri ...

随机推荐

  1. Linux: yum 命令说明

    yum命令是在Fedora和RedHat以及SUSE中基于rpm的软件包管理器,它可以使系统管理人员交互和自动化地更细与管理RPM软件包,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性 ...

  2. 使用蒲公英路由器 X3 设置为网络中继器

    由于我的路由器放的时间比较久没有用了,所以先让路由器来个升级.链接图如下: 在浏览器地址栏中输入  oraybox.com,系统会自动跳到 https://pgybox.oray.com/passpo ...

  3. JAVA 容易忽略的东西

    Java中的取余会出现负数.用Math.floorMod()方法可以掰正,但是也仅限被除数是负数的情况,如果除数是负数,这个没用. 和C不一样,Java中的字符串是不可变字符串,不能修改Java字符串 ...

  4. 数据库 schema含义

    数据库Schema有两种含义,一种是概念上的Schema,指的是一组DDL语句集,该语句集完整地描述了数据库的结构.还有一种是物理上的Schema,指的是数据库中的一个名字空间,它包含一组表.视图和存 ...

  5. centos7下kubernetes(6。运行应用)

    Deployment 从一个例子开始 kubectl run nginx-deployment --image=nginx:1.7.9 --replicas=2 kubectl get deploym ...

  6. jenkins进行andriod打包,上传蒲公英

    环境:macos jenkins sdk gradle 1.构建操作注意: mac电脑上 选择invoke gradle task数值是:clean 2.再创建一个task 然后进行gradle加参数 ...

  7. 【转】iOS弹幕库OCBarrage-如何hold住每秒5000条巨量弹幕

    最近公司做新需求, 原来用的老弹幕库, 已经无法满足需要. 迫不得已自己写了一套弹幕库OCBarrage. 这套弹幕库轻量, 可拓展, 高度自定义, 超高性能, 简单易上手. 无论哪家公司软件的性能绝 ...

  8. day23 Pythonpython 本文re模块

    re模块用于对python的正则表达式的操作. 字符: . 匹配除换行符以外的任意字符 \w 匹配字母或数字或下划线或汉字 \s 匹配任意的空白符 \d 匹配数字 \b 匹配单词的开始或结束 ^ 匹配 ...

  9. Spring Security(二十七):Part II. Architecture and Implementation

    Once you are familiar with setting up and running some namespace-configuration based applications, y ...

  10. 机器学习三剑客之Pandas中DataFrame基本操作

    Pandas 是基于Numpy 的一种工具,是为了解决数据分析任务而创建的.Pandas 纳入了大量库和一些标准的数据模型,提供了高效地操作大型数据集所需的工具.Pandas提供了大量能使我们快速便捷 ...