[Python standard library] data scientific computing library - math

math module official document: https://docs.python.org/3/library/math.html

The math module functions can be divided according to the purposes comprising: number theory and represents a function, a power function and logarithmic functions, trigonometric functions, angle conversion, hyperbolic functions, specific functions and constants

The math module comprising a part of the function of the most commonly used functions as follows :( been identified in red)

Number theory and representation functions
function Features
ceil(x) Of the floating point number x is rounded up, i.e. the smallest integer greater than or equal to x, returns integer value
floor(x) Of the floating point number x rounded down, i.e., less than or equal to the maximum integer x, integer value return
copysign (x, y) x and y values ​​returned to the same number, a floating point type
fabs(x) The absolute value of the number of x, and the floating point
factorial(x) X number of requirements x!, i.e. factorial of x, returns the integer
fmod(x, y) Seeking x/yremainder of fmod()the %similar, except that, fmodin order xto determine the sign of the remainder, %in order yto determine the sign of the remainder
frexp(x) Returns a tuple consisting of a mantissa and exponent x is (m,e)
calculated: x is divided by 0.5 and 1, to give a range of values
2 E value to be within this range, e is the greatest integer meet the requirements, x / 2 e obtain m values
if x is equal to 0, the value of m and e are 0, the absolute value of m ranges from (0.5) between 0.5 and 1 are not included
fsum(iterable) Iterator for each element in the sum the operation and return to floating point
gcd(x, y) Greatest common divisor integers x and y, gcd(0, 0)returns 0
isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0) If the values of a and b is relatively close returns True, otherwise False
rel_tol: maximum relative tolerance, is the maximum allowed difference between a and b, such as to set a tolerance of 5%, the rel_tol=0.05
default tolerance to 1e-09ensure that the two values in approximately the same nine decimal digits. rel_tolIt must be greater than zero
abs_tol: the minimum absolute tolerance: For close to zero useful. abs_tolMust be at least zero
if no error occurs, the result will be:abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
isfinite(x) If x is not infinite, it is returned True, otherwise False(note 0.0 is considered to be limited)
isinf(x) If x is positive infinity or negative infinity is returned True, otherwiseFalse
isnan(x) If x is not a number, the return True, otherwise returnFalse
ldexp(x, i) Return * X (2 I ) value. It is a function of frexp()inverse function
modf(x) Back tuple x integer part and a fractional part composed of
remainder(x, y) IEEE 754 style return x modulo y with respect
to x and limited finite nonzero y, which is the difference x - n * y, where n is an integer closest to the exact value of the quotient of x / y
if x / y is located just between two integers, then the nearest integer for n * even *
remainder r = remainder (x, y) therefore always satisfy abs (r) <= 0.5 * abs (y)
a special case follows the IEEE 754: in particular, remainder (x, math.inf) for any finite x x is
the remainder (x, 0) and the remainder (math.inf, x) raise a ValueError applies to any of NaN x
If the result of the modulo operation is zero, then the x zero will have the same sign
in the use of IEEE 754 binary floating-point platform, the result of this operation can always be fully represented: do not introduce rounding errors
trunc(x) X rounding floating-point numbers (fractional part discarded), returns the integer value
trunc(x)function-with //similar results divisible, except that the trunc(x)value returned by the shaping function, the //value returned is divisible float

Power function and logarithmic function
function Features
exp(x) Return e x , e to the power x times, where e = 2.718281 ... is the natural logarithm base, which is usually higher than Math.E x more accurate or pow (math.e, x)
expm1(x) Returns e x -1, i.e. power minus x-e 1, e = 2.718281 ... which is the base of natural logarithm
log(x[, base]) 返回 x 的自然对数,默认以 e 为基数,base 参数给定时,将 x 的对数返回给定的 base,计算式为:log(x)/log(base)
log1p(x) 返回 x+1 的自然对数 (基数为e) 的值
log2(x) 返回 x 以 2 为底的对数,通常比 log(x, 2) 更准确
log10(x) 返回 x 底为10的对数,通常比 log(x, 10) 更准确
pow(x, y) 返回 x 的 y 次幂,即 xy
sqrt(x) 返回 x 的平方根

三角函数
函数 功能
cos(x) 返回 x 弧度的余弦值
sin(x) 返回 x 弧度的正弦值
tan(x) 返回 x 弧度的正切值
acos(x) 以弧度为单位返回 x 的反余弦值
asin(x) 以弧度为单位返回 x 的反正弦值
atan(x) 以弧度为单位返回 x 的反正切值
atan2(y, x) 以弧度为单位返回 atan(y / x) ,结果在 -pi 和 pi 之间
从原点到点 (x, y) 的平面矢量使该角度与正X轴成正比
atan2() 的点的两个输入的符号都是已知的,因此它可以计算角度的正确象限
例如,atan(1)atan2(1, 1) 都是 pi/4 ,但 atan2(-1, -1)-3*pi/4
hypot(x, y) 返回欧几里德范数,sqrt(x*x + y*y) ,这是从原点到点 (x, y) 的向量长度

角度转换
函数 功能
degrees(x) 将角度 x 从弧度转换为度数
radians(x) 将角度 x 从度数转换为弧度

双曲函数(基于双曲线而非圆来对三角函数进行模拟)
函数 功能
acosh(x) 返回 x 的反双曲余弦值
asinh(x) 返回 x 的反双曲正弦值
atanh(x) 返回 x 的反双曲正切值
cosh(x) 返回 x 的双曲余弦值
sinh(x) 返回 x 的双曲正弦值
tanh(x) 返回 x 的双曲正切值

特殊函数
函数 功能
erf(x) 可用于计算传统的统计函数,如 累积标准正态分布
erfc(x) 返回 x 处的互补误差函数。 互补错误函数 定义为 1.0 - erf(x)。 它用于 x 的大值,从其中减去一个会导致 有效位数损失
gamma(x) 返回 x 处的 伽马函数值
lgamma(x) 返回 Gamma 函数在 x 绝对值的自然对数

常量
函数 功能
math.pi 数学常数 π = 3.141592…,精确到可用精度
math.e 数学常数 e = 2.718281…,精确到可用精度
math.tau 数学常数 τ = 6.283185…,精确到可用精度,Tau 是一个圆周常数,等于 2π,圆的周长与半径之比
math.inf 浮点正无穷大(对于负无穷大,使用 -math.inf )相当于 float('inf') 的输出
math.nan 浮点非数字(NaN)值,相当于 float('nan') 的输出
发布了149 篇原创文章 · 获赞 518 · 访问量 46万+

Guess you like

Origin blog.csdn.net/qq_36759224/article/details/104446136