作者: 上海-vivi 地址:https://github.com/small99/deeptest/tree/master/第一期/上海-vivi 声明:本文已获作者授权转载,著作权归作者所有。 数学函数 #返回数字的绝对值 1 、abs(x)abs(-10)返回10 >>> import math >>> abs(-10) 10 >>> math.fabs(-10) 10.0 #会生成按顺序排在这个输入值之后的最小整数,即四舍五入的入,注意负数的入 2、ceil(x) >>> math.ceil(2.678) 3 >>> math.ceil(-6.66) -6 #截断x小数点后的数字,只留下构成x整数部分的有效数字 3 、trunc(x) >>> math.trunc(3.3) 3 >>> math.trunc(-3.3) -3 #将x转换为不大于它的最大整数 4 、floor(x) >>> math.floor(3.3) 3 >>> math.floor(-3.3) -4 #返回e(自然常数)的x次幂(e**x) 5 、exp(x) >>> math.e 2.718281828459045 >>> math.exp(1) 2.718281828459045 >>> math.exp(2) 7.38905609893065 #返回x的绝对值 6 、fabs(x) >>> math.fabs(-10) 10.0 >>> math.fabs(6.6) 6.6 #log(x)计算以e为底数的x的自然对数 7 、log(x) >>> math.log(10) 2.302585092994046 >>> math.log(4) 1.3862943611198906 #log(x,y)计算以y为底数的x的自然对数 8 、log(x,y) >>> math.log(27,3) 3.0 >>> math.log(64,2) 6.0 #返回以10为底数的x的自然对数,对等于log(x,10) 9 、log10(x) >>> math.log10(1000) 3.0 >>> math.log10(10000) 4.0 #返回一个tuple,其中包含x的小数和整数部分 10、modf(x) >>> math.modf(6.35) (0.34999999999999964, 6.0) #返回x的y次幂的值 11、pow(x,y) >>> math.pow(2,3) 8.0 >>> math.pow(4,3) 64.0 #计算x的平方根,数字不能使复数 12、sqrt(x) >>> math.sqrt(9) 3.0 >>> math.sqrt(36) 6.0 #返回给定参数的最大值 13、max(x1,x2,…) >>> max(2,3,4,7,1,9) 9 #返回给定参数的最小值 14、min(x1,x2,…) >>> min(2,3,4,7,1,9) 1 #返回浮点数x的四舍五入值,如果给出n值,则代表舍入到小数点后的位数 15、round(x,n) >>> round(3.145664) 3 >>> round(3.145664,3) 3.146 #常量 >>> math.e 2.718281828459045 >>> math.pi 3.141592653589793 |
|