-
math模块
2020-03-04 19:42:40math模块 1- math.ceil(num) num向上取整 2- math.floor(num) num向下取整 3- math.modf(num) num小数与整数分离 4- math.sqrt(num) num的开平方(只取正数) -
python安装math模块_python math模块
2020-12-05 14:51:50import mathmath.ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回xcopysign:把y的正负号加到x前面,可以使用0cos:求x的余弦,x必须是弧度degrees:把x从弧度转换成角度e:表示一个常量exp:返回math.e,也就是...import math
math.
ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回x
copysign:把y的正负号加到x前面,可以使用0
cos:求x的余弦,x必须是弧度
degrees:把x从弧度转换成角度
e:表示一个常量
exp:返回math.e,也就是2.71828的x次方
expm1:返回math.e的x(其值为2.71828)次方的值减1
fabs:返回x的绝对值
factorial:取x的阶乘的值
floor:取小于等于x的最大的整数值,如果x是一个整数,则返回自身
fmod:得到x/y的余数,其值是一个浮点数
frexp:返回一个元组(m,e),其计算方式为:x分别除0.5和1,得到一个值的范围
fsum:对迭代器里的每个元素进行求和操作
gcd:返回x和y的最大公约数
hypot:如果x是不是无穷大的数字,则返回True,否则返回False
isfinite:如果x是正无穷大或负无穷大,则返回True,否则返回False
isinf:如果x是正无穷大或负无穷大,则返回True,否则返回False
isnan:如果x不是数字True,否则返回False
ldexp:返回x*(2**i)的值
log:返回x的自然对数,默认以e为基数,base参数给定时,将x的对数返回给定的base,计算式为:log(x)/log(base)
log10:返回x的以10为底的对数
log1p:返回x+1的自然对数(基数为e)的值
log2:返回x的基2对数
modf:返回由x的小数部分和整数部分组成的元组
pi:数字常量,圆周率
pow:返回x的y次方,即x**y
radians:把角度x转换成弧度
sin:求x(x为弧度)的正弦值
sqrt:求x的平方根
tan:返回x(x为弧度)的正切值
trunc:返回x的整数部分
代码:
1 >>> importmath2 >>> math.ceil(2.33)3 3
4 >>> math.copysign(2, -4)5 -2.0
6 >>> math.cos(math.pi/3)7 0.5000000000000001
8 >>> math.degrees(math.pi/3)9 59.99999999999999
10 >>>math.e11 2.718281828459045
12 >>> math.exp(1)13 2.718281828459045
14 >>> math.expm1(1)15 1.718281828459045
16 >>> math.fabs(-2)17 2.0
18 >>> math.factorial(3)19 6
20 >>> math.floor(2.7356)21 2
22 >>> math.fmod(8, 5)23 3.0
24 >>> math.frexp(10)25 (0.625, 4)26 >>> math.fsum([1, 3, 5, 7, 9])27 25.0
28 >>> math.gcd(12, 16)29 4
30 >>> math.hypot(3, 4)31 5.0
32 >>> math.isfinite(0/1)33 True34 >>> math.isinf(222)35 False36 >>> math.isnan(22)37 False38 >>> math.ldexp(5, 2)39 20.0
40 >>> math.log(10)41 2.302585092994046
42 >>>math.log(math.e)43 1.0
44 >>> math.log10(100)45 2.0
46 >>> math.log(10)47 2.302585092994046
48 >>> math.log1p(10)49 2.3978952727983707
50 >>> math.log(11)51 2.3978952727983707
52 >>> math.log2(1024)53 10.0
54 >>> math.log2(16)55 4.0
56 >>>math.modf(math.pi)57 (0.14159265358979312, 3.0)58 >>>math.pi59 3.141592653589793
60 >>> math.pow(3, 4)61 81.0
62 >>> math.radians(45)63 0.7853981633974483
64 >>> math.sin(math.pi/3)65 0.8660254037844386
66 >>> math.sqrt(16)67 4.0
68 >>> math.tan(math.pi/4)69 0.9999999999999999
70 >>> math.trunc(2.56789)71 2
72 >>> math.trunc(-2.56789)73 -2
View Code
-
python中math模块cile_python中math模块常用的方法整理
2020-12-09 17:21:16ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回xcopysign:把y的正负号加到x前面,可以使用0cos:求x的余弦,x必须是弧度degrees:把x从弧度转换成角度e:表示一个常量exp:返回math.e,也就是2.71828的x次方...ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回x
copysign:把y的正负号加到x前面,可以使用0
cos:求x的余弦,x必须是弧度
degrees:把x从弧度转换成角度
e:表示一个常量
exp:返回math.e,也就是2.71828的x次方
expm1:返回math.e的x(其值为2.71828)次方的值减1
fabs:返回x的绝对值
floor:取小于等于x的最大的整数值,如果x是一个整数,则返回自身
fmod:得到x/y的余数,其值是一个浮点数
frexp:返回一个元组(m,e),其计算方式为:x分别除0.5和1,得到一个值的范围
fsum:对迭代器里的每个元素进行求和操作
gcd:返回x和y的最大公约数
hypot:如果x是不是无穷大的数字,则返回True,否则返回False
isfinite:如果x是正无穷大或负无穷大,则返回True,否则返回False
isinf:如果x是正无穷大或负无穷大,则返回True,否则返回False
isnan:如果x不是数字True,否则返回False
ldexp:返回x*(2**i)的值
log:返回x的自然对数,默认以e为基数,base参数给定时,将x的对数返回给定的base,计算式为:log(x)/log(base)
log10:返回x的以10为底的对数
log1p:返回x+1的自然对数(基数为e)的值
log2:返回x的基2对数
modf:返回由x的小数部分和整数部分组成的元组
pi:数字常量,圆周率
pow:返回x的y次方,即x**y
radians:把角度x转换成弧度
sin:求x(x为弧度)的正弦值
sqrt:求x的平方根
tan:返回x(x为弧度)的正切值
trunc:返回x的整数部分
ceil
#取大于等于x的最小的整数值,如果x是一个整数,则返回x
ceil(x)
Return the ceiling of x as an int.
This is the smallest integral value >= x.
>>> math.ceil(4.01)
5
>>> math.ceil(4.99)
5
>>> math.ceil(-3.99)
-3
>>> math.ceil(-3.01)
-3
copysign
#把y的正负号加到x前面,可以使用0
copysign(x, y)
Return a float with the magnitude (absolute value) of x but the sign
of y. On platforms that support signed zeros, copysign(1.0, -0.0)
returns -1.0.
>>> math.copysign(2,3)
2.0
>>> math.copysign(2,-3)
-2.0
>>> math.copysign(3,8)
3.0
>>> math.copysign(3,-8)
-3.0
cos
#求x的余弦,x必须是弧度
cos(x)
Return the cosine of x (measured in radians).
#math.pi/4表示弧度,转换成角度为45度
>>> math.cos(math.pi/4)
0.7071067811865476
math.pi/3表示弧度,转换成角度为60度
>>> math.cos(math.pi/3)
0.5000000000000001
math.pi/6表示弧度,转换成角度为30度
>>> math.cos(math.pi/6)
0.8660254037844387
degrees
#把x从弧度转换成角度
degrees(x)
Convert angle x from radians to degrees.
>>> math.degrees(math.pi/4)
45.0
>>> math.degrees(math.pi)
180.0
>>> math.degrees(math.pi/6)
29.999999999999996
>>> math.degrees(math.pi/3)
59.99999999999999
e
#表示一个常量
>>> math.e
2.718281828459045
exp
#返回math.e,也就是2.71828的x次方
exp(x)
Return e raised to the power of x.
>>> math.exp(1)
2.718281828459045
>>> math.exp(2)
7.38905609893065
>>> math.exp(3)
20.085536923187668
expm1
#返回math.e的x(其值为2.71828)次方的值减1
expm1(x)
Return exp(x)-1.
This function avoids the loss of precision involved in the direct evaluation of exp(x)-1 for small x.
>>> math.expm1(1)
1.718281828459045
>>> math.expm1(2)
6.38905609893065
>>> math.expm1(3)
19.085536923187668
fabs
#返回x的绝对值
fabs(x)
Return the absolute value of the float x.
>>> math.fabs(-0.003)
0.003
>>> math.fabs(-110)
110.0
>>> math.fabs(100)
100.0
factorial
#取x的阶乘的值
factorial(x) -> Integral
Find x!. Raise a ValueError if x is negative or non-integral.
>>> math.factorial(1)
1
>>> math.factorial(2)
2
>>> math.factorial(3)
6
>>> math.factorial(5)
120
>>> math.factorial(10)
3628800
floor
#取小于等于x的最大的整数值,如果x是一个整数,则返回自身
floor(x)
Return the floor of x as an int.
This is the largest integral value <= x.
>>> math.floor(4.1)
4
>>> math.floor(4.999)
4
>>> math.floor(-4.999)
-5
>>> math.floor(-4.01)
-5
fmod
#得到x/y的余数,其值是一个浮点数
fmod(x, y)
Return fmod(x, y), according to platform C. x % y may differ.
>>> math.fmod(20,3)
2.0
>>> math.fmod(20,7)
6.0
frexp
#返回一个元组(m,e),其计算方式为:x分别除0.5和1,得到一个值的范围,
#2**e的值在这个范围内,e取符合要求的最大整数值,然后x/(2**e),得到m的值
#如果x等于0,则m和e的值都为0,m的绝对值的范围为(0.5,1)之间,不包括0.5和1
frexp(x)
Return the mantissa and exponent of x, as pair (m, e).
m is a float and e is an int, such that x = m * 2.**e.
If x is 0, m and e are both 0. Else 0.5 <= abs(m) < 1.0.
>>> math.frexp(10)
(0.625, 4)
>>> math.frexp(75)
(0.5859375, 7)
>>> math.frexp(-40)
(-0.625, 6)
>>> math.frexp(-100)
(-0.78125, 7)
>>> math.frexp(100)
(0.78125, 7)
fsum
#对迭代器里的每个元素进行求和操作
fsum(iterable)
Return an accurate floating point sum of values in the iterable.
Assumes IEEE-754 floating point arithmetic.
>>> math.fsum([1,2,3,4])
10.0
>>> math.fsum((1,2,3,4))
10.0
>>> math.fsum((-1,-2,-3,-4))
-10.0
>>> math.fsum([-1,-2,-3,-4])
-10.0
gcd
#返回x和y的最大公约数
gcd(x, y) -> int
greatest common divisor of x and y
>>> math.gcd(8,6)
2
>>> math.gcd(40,20)
20
>>> math.gcd(8,12)
4
hypot
#得到(x**2+y**2),平方的值
hypot(x, y)
Return the Euclidean distance, sqrt(x*x + y*y).
>>> math.hypot(3,4)
5.0
>>> math.hypot(6,8)
10.0
isfinite
#如果x是不是无穷大的数字,则返回True,否则返回False
isfinite(x) -> bool
Return True if x is neither an infinity nor a NaN, and False otherwise.
>>> math.isfinite(100)
True
>>> math.isfinite(0)
True
>>> math.isfinite(0.1)
True
>>> math.isfinite("a")
>>> math.isfinite(0.0001)
True
isinf
#如果x是正无穷大或负无穷大,则返回True,否则返回False
isinf(x) -> bool
Return True if x is a positive or negative infinity, and False otherwise.
>>> math.isinf(234)
False
>>> math.isinf(0.1)
False
isnan
#如果x不是数字True,否则返回False
isnan(x) -> bool
Return True if x is a NaN (not a number), and False otherwise.
>>> math.isnan(23)
False
>>> math.isnan(0.01)
False
ldexp
#返回x*(2**i)的值
ldexp(x, i)
Return x * (2**i).
>>> math.ldexp(5,5)
160.0
>>> math.ldexp(3,5)
96.0
log
#返回x的自然对数,默认以e为基数,base参数给定时,将x的对数返回给定的base,计算式为:log(x)/log(base)
log(x[, base])
Return the logarithm of x to the given base.
If the base not specified, returns the natural logarithm (base e) of x.
>>> math.log(10)
2.302585092994046
>>> math.log(11)
2.3978952727983707
>>> math.log(20)
2.995732273553991
log10
#返回x的以10为底的对数
log10(x)
Return the base 10 logarithm of x.
>>> math.log10(10)
1.0
>>> math.log10(100)
2.0
#即10的1.3次方的结果为20
>>> math.log10(20)
1.3010299956639813
log1p
#返回x+1的自然对数(基数为e)的值
log1p(x)
Return the natural logarithm of 1+x (base e).
The result is computed in a way which is accurate for x near zero.
>>> math.log(10)
2.302585092994046
>>> math.log1p(10)
2.3978952727983707
>>> math.log(11)
2.3978952727983707
log2
#返回x的基2对数
log2(x)
Return the base 2 logarithm of x.
>>> math.log2(32)
5.0
>>> math.log2(20)
4.321928094887363
>>> math.log2(16)
4.0
modf
#返回由x的小数部分和整数部分组成的元组
modf(x)
Return the fractional and integer parts of x. Both results carry the sign
of x and are floats.
>>> math.modf(math.pi)
(0.14159265358979312, 3.0)
>>> math.modf(12.34)
(0.33999999999999986, 12.0)
pi
#数字常量,圆周率
>>> print(math.pi)
3.141592653589793
pow
#返回x的y次方,即x**y
pow(x, y)
Return x**y (x to the power of y).
>>> math.pow(3,4)
81.0
>>>
>>> math.pow(2,7)
128.0
radians
#把角度x转换成弧度
radians(x)
Convert angle x from degrees to radians.
>>> math.radians(45)
0.7853981633974483
>>> math.radians(60)
1.0471975511965976
sin
#求x(x为弧度)的正弦值
sin(x)
Return the sine of x (measured in radians).
>>> math.sin(math.pi/4)
0.7071067811865475
>>> math.sin(math.pi/2)
1.0
>>> math.sin(math.pi/3)
0.8660254037844386
sqrt
#求x的平方根
sqrt(x)
Return the square root of x.
>>> math.sqrt(100)
10.0
>>> math.sqrt(16)
4.0
>>> math.sqrt(20)
4.47213595499958
tan
#返回x(x为弧度)的正切值
tan(x)
Return the tangent of x (measured in radians).
>>> math.tan(math.pi/4)
0.9999999999999999
>>> math.tan(math.pi/6)
0.5773502691896257
>>> math.tan(math.pi/3)
1.7320508075688767
trunc
#返回x的整数部分
trunc(x:Real) -> Integral
Truncates x to the nearest Integral toward 0. Uses the __trunc__ magic method.
>>> math.trunc(6.789)
6
>>> math.trunc(math.pi)
3
>>> math.trunc(2.567)
2
内容来源于网络如有侵权请私信删除
-
12.1Math模块
2019-04-02 09:17:22Math ... //将值向上取整数 double value = Math.ceil(12.1); System.out.println(value); //将值向下取整 double value2 = Math.floor(12.9); System.out.println(value2); ...Math
public static void main(String[] args) { //将值向上取整数 double value = Math.ceil(12.1); System.out.println(value); //将值向下取整 double value2 = Math.floor(12.9); System.out.println(value2); //四舍五入 double value3 = Math.round(12.3); System.out.println(value3); double value4 = Math.pow(4, 3); System.out.println(value4); //随机数,Random类 Random r = new Random(); int result1 = r.nextInt(); //返回一个随机整数 double result2 = r.nextDouble(); //返回一个随机的小数 System.out.println(result1); System.out.println(result2); /** * 在java只生成的随机数称为伪随机数。 * 生成随机数的时候,要求我们必须传递一个种子进去。种子是一样的 每次生成的随机数都一样 * new Random 默认加了种子,以当前系统时间作为种子 */ Random r2 = new Random(); int res = r2.nextInt(); int res3 = r2.nextInt(); System.out.println(res); System.out.println(res3); Random r3 = new Random(); int res2 = r3.nextInt(); int res4 = r3.nextInt(); System.out.println(res2); System.out.println(res4); //生成一个四位数以内的随机数 int res5 = r3.nextInt(9999); System.out.println(res5); //随机数第二种用法 默认产生的随机数0-1(不包含1) double res6 = Math.random(); System.out.println(res6); //产生一个10-20的随机数 double res7 = res6*10+10; System.out.println(res7); }
-
python的math模块_(转)python中math模块常用的方法整理
2020-12-05 14:50:03原文:https://www.cnblogs.com/renpingsheng/p/7171950.html#ceilceil:取大于等于x的最小的整数值,如果x是一个整数,则返回xcopysign:把y的正负号加到x前面,可以使用0cos:求x的余弦,x必须是弧度degrees:把x从... -
python专题math模块
2020-05-11 19:28:25math模块关于数学一些基础函数的操作,主要是三角函数,取整,对数函数,指数函数等常用函数操作; 公众号:知识追寻者 知识追寻者(Inheriting the spirit of open source, Spreading technology knowledge;) 二 ... -
python math模块
2018-04-19 11:23:00ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回x copysign:把y的正负号加到x前面,可以使用0 cos:求x的余弦,x必须是弧度 degrees:把x从弧度转换成角度 e:表示一个常量 exp:返回math.e,也就是2.... -
python中math模块
2019-11-07 11:40:14python中math模块常用的方法整理 ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回x copysign:把y的正负号加到x前面,可以使用0 cos:求x的余弦,x必须是弧度 degrees:把x从弧度转换成角度 e:表示一个... -
python math 模块
2018-07-25 21:33:01ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回x copysign:把y的正负号加到x前面,可以使用0 cos:求x的余弦,x必须是弧度 degrees:把x从弧度转换成角度 e:表示一个常量 exp:返回math.e,也就是2.... -
python——之math模块
2018-05-25 12:28:08转载自:https://www.cnblogs.com/renpingsheng/p/7171950.htmlpython的math模块,类似于C++的cmath库python中math模块常用的方法整理ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回xcopysign:把y的正负... -
python中math模块常用的方法
2018-10-20 14:47:20python中math模块常用的方法 ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回x copysign:把y的正负号加到x前面,可以使用0 cos:求x的余弦,x必须是弧度 degrees:把x从弧度转换成角度 e:表示一个常量 exp:... -
python中常用math模块函数总结
2019-06-16 22:11:301、math模块-数论和表示函数(Number-Theoretical and Representation Functions) 函数 使用说明 ceil(x) 取大于等于x的最小的整数值,如果x是一个整数,则返回x copysign(x,y) 把y的正负号加到x前面... -
python中math模块的常用详解
2019-02-22 22:11:00python中math模块常用的方法整理 ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回x copysign:把y的正负号加到x前面,可以使用0 cos:求x的余弦,x必须是弧度 degrees:把x从弧度转换成角度 e:... -
python中math模块常用的方法整理
2018-12-05 09:11:00python中math模块常用的方法整理 ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回x copysign:把y的正负号加到x前面,可以使用0 cos:求x的余弦,x必须是弧度 degrees:把x从弧度转换成角度 e:... -
python中math power_python中math模块常用的方法整理
2020-12-04 16:39:37ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回xcopysign:把y的正负号加到x前面,可以使用0cos:求x的余弦,x必须是弧度degrees:把x从弧度转换成角度e:表示一个常量exp:返回math.e,也就是2.71828的x次方... -
python cmath模块_python中math模块常用的方法整理
2021-03-17 01:08:47ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回xcopysign:把y的正负号加到x前面,可以使用0cos:求x的余弦,x必须是弧度degrees:把x从弧度转换成角度e:表示一个常量exp:返回math.e,也就是2.71828的x次方... -
Python math模块中的方法
2018-05-25 16:56:51ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回xcopysign:把y的正负号加到x前面,可以使用0cos:求x的余弦,x必须是弧度degrees:把x从弧度转换成角度e:表示一个常量exp:返回math.e,也就是2.71828的x次方... -
python前端模块_python中math模块常用的方法整理
2020-12-11 21:48:14ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回xcopysign:把y的正负号加到x前面,可以使用0cos:求x的余弦,x必须是弧度degrees:把x从弧度转换成角度e:表示一个常量exp:返回math.e,也就是2.71828的x次方... -
python中math的方法_python中math模块常用的方法整理
2020-12-05 14:51:52ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回xcopysign:把y的正负号加到x前面,可以使用0cos:求x的余弦,x必须是弧度degrees:把x从弧度转换成角度e:表示一个常量exp:返回math.e,也就是2.71828的x次方... -
python内置模块求绝对值_Python 基础入门 7_4 内置模块(Math模块以及随机数模块)...
2020-12-05 15:55:12#Number数据类型的数学功能,需要引入math包(即import math)"""绝对值:abs(变量)取最大值: max(多个变量或常量,2个起,用逗号隔开)取最小值: min(多个变量或常量,2个起,用逗号隔开)求x的y次方: pow( 原数,指数... -
数值和数学计算(一)、math模块
2019-08-07 16:10:44取大于等于x的最小的整数值,如果x是一个整数,则返回x >>> math.ceil(4.12) 5 把y的正负号加到x前面,可以使用0 >>> math.copysign(2,-3) -2.0 求x的余弦,x必须是弧度 ... -
python取整数部分的几种方法
2021-03-06 12:01:57python取整数部分的几种方法 1、向下取整:int() >>> a = 14.38 >>> int(a) 14 2、向上取整:ceil() 使用ceil()方法时需要导入math模块,例如 >>> import math >>> math.ceil...