Math 모듈은 파이썬에 내장된 수학 연산을 위한 모듈이다. 데이터 사이언스에서는 NumPy를 주로 사용하기 때문에 해당 문서에서는 간단하게 설명한다.
Math는 실수 영역의 수학에 대한 함수를 제공하는 모듈이다.
import math
$\pi = 3.141592$: math.pi
math.pi
$e = 2.718281$: math.e
math.e
$\infin$: math.inf
math.inf
Not a number(NaN): math.nan
math.nan
순열: math.perm(n, k)
math.perm(5, 2)
# 20
조합: math.comb(n, k)
math.comb(n, k)
# 10
계승: math.factorial(x)
math.factorial(5)
# 120
올림: math.ceil(x)
math.ceil(3.141592)
# 4
내림: math.floor(x)
math.floor(3.141592)
# 3
최대 공약수: math.gcd(*integers)
math.gcd(12, 15)
# 3
최소 공배수: math.lcm(*integers)
math.gcd(12, 15)
# 60