Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Python Mathematical Functions

Math module provide many useful mathematical functions which makes our life really easy.  This module is always available as a part of python standard library.

Math Number-theoretic and Representation Functions

These function is used to control the representation of mathematical numbers in python.

ceil()floor()gcd()isnan()
copysign()fmod()isclose()ldexp()
 fabs()frexp()isfinite()modf()
 factorial()fsum()isinf()trunc()

Math Power and Logarithmic Functions

These function is useful for finding log and power of given numbers.

exp()log()log2()pow()
expm1()log1p()log10()sqrt()

Math Trigonometric Functions

These functions are used to solve the trigonometric problems such as sine, cosine, etc.

 acos() atan() cos() sin()
 asin() atan2() hypot() tan()

Math Angular Conversion Functions

Angular function is used to convert degree into radian and radian into degree.

degrees()radians()

Math Hyperbolic Functions

These mathematical function is used to find hyperbolic of sine, cosine, tan, etc.

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

Math Special Functions

These are some special functions.

erf()erfc()gamma()lgamma()

Math Constants

These are the constant values exist in python math module.

pitaunan
einf

Please click on any function name for more detail, examples and code snippets.

Number-theoretic and Representation Functions

 Function Name Function Description
 ceil(x)Return ceiling value (round up to the nearest integer) of numeric expression n. The return value is not less than n, instead, it is equal to or greater than n.
 copysign(x, y)Return a float value which is consist of the absolute value or the magnitude of the parameter x and the sign of parameter y.
 fabs(x)Return an absolute or positive value.
 factorial(x)Return an integer value after calculating the factorial.
 floor(x)Return the largest integer (2.x) / float (3.x) not greater than given value x.
 fmod(x, y)Return a floating point number value after calculating module of given parameters x and y.
 frexp(x)Returns mantissa and exponent as a pair (m, e) value of a given number x.
 fsum(iterable)Returns an accurate sum of any iterable as a floating point number.
 gcd(a, b)Return an absolute/positive integer value after calculating the GCD of given parameters x and y.
 isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0) If a and b are close to each other then this function return true otherwise false.
 isfinite(x)Return either True or False.
 isinf(x)Return either True or False.
 isnan(x)Return either True or False.
 ldexp(x, i)Return the value of x * (2**i).
 modf(x)Return the fractional and integer part of x which have the same signs as x and also integer part will return a float value.
 trunc(x)Return a real value x truncated to an Integral which is most likely an integer.

Power and Logarithmic Functions

Function NameFunction Description
exp(x)Returns a floating point number after calculating the expression e**x.
expm1(x) Return e**x - 1.
log(x[, base]) Return the logarithm of x for the given base.
log1p(x) Return the natural logarithm of 1+x (base e).
log2(x) Return base 2 logarithm of x which is the input value.
log10(x) Return base 10 logarithm of given input (x – parameter).
pow(x, y) Return the value of x raised to the power y.
sqrt(x)Return an integer or a floating point number after calculating square root. The return value will always be greater thanzero.

Trigonometric Functions

 Function Name Function Description
acos(x)Return the inverse of cosine in radians.
asin(x)Return a floating point number which is the inverse of sine in radians.
atan(x) Return the the inverse of tan in radians.
atan2(y, x) Return atan(y / x) in radians.
cos(x) Return the cosine in radians.
hypot(x, y)Return the vector length from origin point to the point (x, y).  Euclidean norm which is sqrt(x*x + y*y).
sin(x)Return the sine in radians.
tan(x) Return the tangent in radians.

Angular Conversion

Function NameFunction Description
degrees(x)Converts radians to degrees.
radians(x)Converts degrees into radians.

Hyperbolic Functions

Function NameFunction Description
acosh(x)Return inverse hyperbolic cosine.
asinh(x)Return inverse hyperbolic sine.
atanh(x)Return inverse hyperbolic tangent.
cosh(x)Return hyperbolic cosine.
sinh(x)Return hyperbolic sine.
tanh(x)Return hyperbolic tan.

Special Functions

Function NameFunction Description
erf(x) Return the error function for the given value. This function is new in python 3.2 version.
erfc(x) Return the complementary error function for the given value. This function is new in python 3.2 version.
gamma(x) Return the gamma function for given input. This function is new in python 3.2 version.
lgamma(x) Return the natural logarithm of absolute value of gamma function for given input. This function is new in python 3.2 version.

Constants

Function NameFunction Description
math.piPi (π) is equal to the value 3.141592…, to the available precision.
math.ee is equal to the value 2.718281…, to the available precision.
math.tautau (τ) is equal to the value 6.283185…, to the available precision. Its the ratio of a circle’s circumference to its radius. This constant is new in python 3.6 version.
math.infinf is equal to the positive infinity in floating points and for negative infinity we use -math.inf. This constant is new in python 3.5 version.
math.nannan represents not a number value(NaN).This constant is new in python 3.5 version.

 

LearnAndLearn.com © 2018 - All rights reserved