What math functions are built in into Python?

Christy 66 Published: 08/14/2024

What math functions are built in into Python?

I'm happy to respond in English!

Python has an extensive range of mathematical functions built-in, making it a popular choice for scientific computing, data analysis, and machine learning applications. Here's a comprehensive list of the most commonly used math functions:

Trigonometric Functions

math.sin(x): Returns the sine of x.

math.cos(x): Returns the cosine of x. math.tan(x): Returns the tangent of x. math.asin(y), math.acos(y), and math.atan(y): Return the arc sine, arc cosine, and arc tangent of y, respectively.

Hyperbolic Functions

math.sinh(x): Returns the hyperbolic sine of x. math.cosh(x): Returns the hyperbolic cosine of x. math.tanh(x): Returns the hyperbolic tangent of x.

Exponential and Logarithmic Functions

math.exp(x): Returns the exponential of x, i.e., e^x. math.log(x): Returns the natural logarithm (base-e) of x. math.log10(x): Returns the base-10 logarithm of x.

Power and Root Functions

math.pow(x, y): Returns x raised to the power of y. math.sqrt(x): Returns the square root of x.

Statistical Functions

math.mean(data): Returns the mean (average) of the elements in data. math.median(data): Returns the median (middle value) of the elements in data. math.std(data): Returns the standard deviation of the elements in data.

Complex Functions

cmath.sqrt(-1): Returns the imaginary unit (i). cmath.exp(x + i*y), cmath.log(x + i*y): Perform complex exponential and logarithmic operations.

Special Functions

math.gamma(x): Returns the gamma function of x. math.erf(x), math.erfc(x), math.erfi(x), and math.dawsn(x): Implement various error functions (Gaussian, complementary Gaussian, imaginary error, and Dawson's integral).

Other Functions

math.modf(x): Returns the fractional part of x as a tuple (f, i). math.fmod(x, y): Returns the remainder of dividing x by y.

These built-in math functions are essential for performing various mathematical operations in Python. You can import them from the math module and use them to create more complex calculations.

Remember, you can always check the documentation for each function or refer to the Python documentation for more information on their usage and behavior.

Python math functions list pdf

I'm happy to help! Here is the list of Python math functions with a brief description and examples:

Trigonometric Functions

math.sin(x) - Returns the sine of x (in radians). Example: math.sin(math.pi/2) returns 1.0. math.cos(x) - Returns the cosine of x (in radians). Example: math.cos(0) returns 1.0. math.tan(x) - Returns the tangent of x (in radians). Example: math.tan(math.pi/4) returns 1.0.

Hyperbolic Functions

math.sinh(x) - Returns the hyperbolic sine of x. Example: math.sinh(0) returns 0.0. math.cosh(x) - Returns the hyperbolic cosine of x. Example: math.cosh(0) returns 1.0. math.tanh(x) - Returns the hyperbolic tangent of x. Example: math.tanh(0) returns 0.0.

Exponential and Logarithmic Functions

math.exp(x) - Returns the base-e exponential of x. Example: math.exp(0) returns 1.0. math.log(x) - Returns the natural logarithm of x (base-e). Example: math.log(math.e) returns 1.0.

Power and Root Functions

math.pow(x, y) - Returns the value of x raised to the power y. Example: math.pow(2, 3) returns 8.0. math.sqrt(x) - Returns the square root of x (rounded down). Example: math.sqrt(4) returns 2.0.

Miscellaneous Functions

math.atan2(y, x) - Returns the arctangent of y/x in radians. Example: math.atan2(1, 1) returns math.pi/4 (approximately). math.hypot(x, y) - Returns the Euclidean norm (magnitude) of the vector (x, y). Example: math.hypot(3, 4) returns math.sqrt(25) (approximately).

Constants

math.pi - The mathematical constant pi. math.e - The base of natural logarithms.

Other Functions

math.modf(x) - Returns a tuple containing the fractional part and integer part of x. Example: math.modf(3.7) returns (0.7, 3). math.fmod(x, y) - Returns the remainder of dividing x by y. Example: math.fmod(10, 3) returns 1.

Statistical Functions

math.erf(x) - The error function. math.erfc(x) - The complementary error function. math.gamma(x) - The gamma function. math.lgamma(x) - The natural logarithm of the gamma function.

This is just a small selection of the many mathematical functions available in Python's math module. You can refer to the official Python documentation or other online resources for more information and examples.

Please note that this response only includes English text, as per your request. However, please keep in mind that I'll be happy to help with any further questions you may have, including answers in Simplified Chinese if needed!