首页 > 编程知识 正文

python37.dll,找不到python37.dll

时间:2023-05-05 06:43:39 阅读:272704 作者:1992

数学运算模块:math与cmath

作者:Shawn
python3.7
文档:
https://docs.python.org/3/library/math.html
https://docs.python.org/3/library/cmath.html

数学运算模块:math与cmath math模块 常规部分 math.ceil(x)math.copysign(x, y)math.fabs(x)math.factorial(x)math.floor(x)math.fmod(x, y)math.frexp(x)math.fsum(iterable)math.gcd(a, b)math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)math.isfinite(x)math.isinf(x)math.isnan(x)math.ldexp(x, i)math.modf(x)math.remainder(x, y)math.trunc(x) 指数、对数部分 math.exp(x)math.expm1(x)math.log(x[, base])math.log1p(x)math.log2(x)math.log10(x)math.pow(x, y)math.sqrt(x) 三角函数部分 math.degrees(x)与math.radians(x)math.acos(x)math.asin(x)math.atan(x)math.atan2(y, x)math.cos(x)math.sin(x)math.tan(x)math.hypot(x, y)math.acosh(x)math.asinh(x)math.atanh(x)math.cosh(x)math.sinh(x)math.tanh(x) 特殊函数部分 math.erf(x)math.erfc(x)math.gamma(x)math.lgamma(x) 常数部分 math.pimath.emath.taumath.infmath.nan cmath模块 坐标转换 cmath.phase(x)cmath.polar(x)cmath.rect(r, phi) 指数对数部分 cmath.exp(x)cmath.log(x[, base])cmath.log10(x)cmath.sqrt(x) 三角函数部分 cmath.acos(x)cmath.asin(x)cmath.atan(x)cmath.cos(x)cmath.sin(x)cmath.tan(x)cmath.acosh(x)cmath.asinh(x)cmath.atanh(x)cmath.cosh(x)cmath.sinh(x)cmath.tanh(x) 判断部分 cmath.isfinite(x)cmath.isinf(x)cmath.isnan(x)cmath.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0) 常数部分 cmath.picmath.ecmath.taucmath.infcmath.infjcmath.nancmath.nanj

math模块 其实不起眼的math里加进去了很多黑科技。 常规部分 math.ceil(x) 向上取整 >>> import math>>> math.ceil(0.0)0>>> math.ceil(0.1)1>>> math.ceil(41.1)42 math.copysign(x, y) copy符号返回x的绝对值和y的符号(对不起,这是我和他的孩子) >>> import math>>> math.copysign(1, -0.0)-1.0>>> math.copysign(-1, 0.0)1.0>>> math.copysign(-1, -0.0)-1.0>>> math.copysign(1, 0)1.0 math.fabs(x) 返回绝对值math.fabs()与内置函数abs()的区别:
fabs需要import math后才能调用,abs可以直接使用abs可以用于复数而fabs不可以。 >>> math.fabs(-8)8.0>>> abs(-8)8>>> abs(1+1.0j)1.4142135623730951>>> math.fabs(1+1.0j)Traceback (most recent call last): File "<pyshell#12>", line 1, in <module> math.fabs(1+1.0j)TypeError: can't convert complex to float math.factorial(x) 这个函数竟然可以返回x!2乘3竟然等于3!(返回x的阶乘) >>> math.factorial(3)6>>> math.factorial(10)3628800 math.floor(x) 向下取整 >>> math.floor(0.0)0>>> math.floor(0.1)0>>> math.floor(-0.1)-1>>> math.floor(42.9)42 math.fmod(x, y) 取模运算与路人运算符号%的区别:
fmod默认返回浮点数对于x、y符号一致时,%与fmod结果一致但x、y符号不一致时,结果不同详见取模运算 >>> 3%21>>> 3%-2-1>>> -3%21>>> 3.1%30.10000000000000009>>> math.fmod(3, 2)1.0>>> math.fmod(3, -2)1.0>>> math.fmod(-3, 2)-1.0>>> math.fmod(3.1, 3)0.10000000000000009>>> math.fmod(-7, 4)-3.0>>> (-7)%41>>> math.fmod(-7, -4)-3.0>>> (-7)%(-4)-3 math.frexp(x) 将x分解为尾数与指数
x = 尾数 * 2^指数 >>> math.frexp(3)(0.75, 2)>>> 0.75*2**23.0>>> math.frexp(32)(0.5, 6)>>> 0.5*2**632.0>>> math.frexp(-32)(-0.5, 6) math.fsum(iterable) 功能同内置函数sum(),但精度更高 >>> sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])0.9999999999999999>>> fsum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])1.0 math.gcd(a, b) 一键返回最大公约数 >>> math.gcd(32, 33)1>>> math.gcd(32, 34)2>>> math.gcd(32, 64)32 math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)

“接近”判断
abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)

若:

rel_tol=xabs_tol=ymath.isclose(a, b, rel_tol=x, abs_tol=y)翻译成:
a与b“接近”的判定条件是:
a与b的差距是否小于ab较大的那个乘以x或ab差距小于y翻译v2:
ab,你和你女朋友x你们的感情y有没有房“你和你女朋友会不会结婚取决于你们的感情或你们有没有房。” >>> math.isclose(3,5,rel_tol=0.2, abs_tol=0.0)False>>> math.isclose(3,5,rel_tol=0.5, abs_tol=0.0)True>>> math.isclose(3,5,rel_tol=0.2, abs_tol=2.0)True math.isfinite(x) 判断x有限或者不是nan >>> math.isfinite(float('nan'))False>>> math.isfinite(float('NaN'))False>>> math.isfinite(1)True math.isinf(x) 判断x是否为正负无限 math.isnan(x) 判断x是否为nan math.ldexp(x, i) math.frexp(x)的逆运算 >>> math.frexp(32)(0.5, 6)>>> math.ldexp(0.5, 6)32.0 math.modf(x) 分离x的整数和小数部分 >>> math.modf(3.1)(0.10000000000000009, 3.0)>>> math.modf(-3.3)(-0.2999999999999998, -3.0) math.remainder(x, y) 符合IEEE 754标准的求余…… >>> math.remainder(5, 2)1.0>>> math.remainder(-7, 4)1.0>>> math.remainder(-7, -4)1.0>>> math.remainder(7, 4)-1.0>>> math.remainder(7, -4)-1.0 math.trunc(x) 截断x的小数部分 >>> math.trunc(32)32>>> math.trunc(32.1)32>>> math.trunc(32.00000000001)32>>> math.trunc(-233.2)-233 指数、对数部分 math.exp(x) e为底的指数 >>> math.exp(0)1.0>>> math.exp(1)2.718281828459045 math.expm1(x) math.expm1(x)=exp(x) - 1 >>> math.expm1(0)0.0>>> math.expm1(1)1.718281828459045 math.log(x[, base]) 对数 >>> math.log(math.e,math.e)1.0>>> math.log(1,math.e)0.0 math.log1p(x) math.log1p(x)=math.log(x+1,math.e) >>> math.log1p(math.e-1)1.0>>> math.log1p(0)0.0 math.log2(x) 二为底数 >>> math.log2(4)2.0>>> math.log2(1024)10.0 math.log10(x) 十为底数 >>> math.log10(10)1.0>>> math.log10(10000)4.0 math.pow(x, y) 指数运算 >>> math.pow(2, 0)1.0>>> math.pow(2, 10)1024.0 math.sqrt(x) 平方根运算 >>> math.sqrt(4)2.0>>> math.sqrt(16)4.0 三角函数部分 运算函数皆默认以弧度值返回。 math.degrees(x)与math.radians(x) 角度与弧度的互换 math.acos(x) arc cosine math.asin(x) arc sine math.atan(x) arc tangent math.atan2(y, x) 方便调节圆上计算路径的math.atan(x) math.cos(x) cosine math.sin(x) sine math.tan(x) tangent math.hypot(x, y) 勾股定理求斜边 >>> math.hypot(3, 4)5.0 math.acosh(x) inverse hyperbolic cosine of x math.asinh(x) inverse hyperbolic sine of x math.atanh(x) inverse hyperbolic tangent of x math.cosh(x) hyperbolic cosine of x math.sinh(x) hyperbolic sine of x math.tanh(x) hyperbolic tangent of x 特殊函数部分 math.erf(x) 返回x处的误差函数 math.erfc(x) 返回x处的互补误差函数math.erfc(x)= 1.0-math.erf(x) math.gamma(x) 返回x处的gamma函数 math.lgamma(x) 返回x处的自然对数gamma函数 >>> math.log(math.gamma(3))0.6931471805599453>>> math.lgamma(3)0.693147180559945 常数部分 math.pi 宇宙真理1 math.e 宇宙真理2 math.tau 两倍的宇宙真理1math.tau=math.pi*2 math.inf 正无穷,加个负号变负无穷可以直接用float(‘inf’)表达 >>> math.isinf(float('inf'))True>>> math.isinf(math.inf)True math.nan not a number一般见于上限爆了等神秘操作可直接用float(‘nan’)表达 cmath模块 cmath模块旨在进行复数运算。这一部分用到的就很少了。 坐标转换 cmath.phase(x) 复数的角度 >>> phase(complex(-1.0, 0.0))3.141592653589793>>> phase(complex(-1.0, -0.0))-3.141592653589793 cmath.polar(x) 复数转为极坐标polar(x)=(abs(x), phase(x)) cmath.rect(r, phi) 极坐标转换成普通复数形式
r * (math.cos(phi) + math.sin(phi)*1j) 指数对数部分 cmath.exp(x) 复数版本 cmath.log(x[, base]) 复数版本 cmath.log10(x) 复数版本 cmath.sqrt(x) 复数版本 三角函数部分 cmath.acos(x) 复数版本 cmath.asin(x) 复数版本 cmath.atan(x) 复数版本 cmath.cos(x) 复数版本 cmath.sin(x) 复数版本 cmath.tan(x) 复数版本 cmath.acosh(x) 复数版本 cmath.asinh(x) 复数版本 cmath.atanh(x) 复数版本 cmath.cosh(x) 复数版本 cmath.sinh(x) 复数版本 cmath.tanh(x) 复数版本 判断部分 cmath.isfinite(x) 实虚全有限才为True cmath.isinf(x) 实虚任意一个为infinity即为True cmath.isnan(x) 实虚任意一个为nan即为True cmath.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0) 同math版本,用abs比较故不受影响 常数部分 cmath.pi 同math版本 cmath.e 同math版本 cmath.tau 同math版本 cmath.inf 同math版本 cmath.infj inf的虚部版本
complex(0.0, float(‘inf’)) cmath.nan 同math版本 cmath.nanj nan虚部版本
complex(0.0, float(‘nan’))

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。