math는 기본 수학 함수를, statistics는 통계 함수를 제공하는 표준 라이브러리입니다. NumPy 없이도 기본적인 수학/통계 연산이 가능합니다.
언제 이 치트시트를 보나?
- 제곱근, 로그, 삼각함수 등이 필요할 때
- 평균, 중앙값, 표준편차 등 기초 통계가 필요할 때
- NumPy 없이 가벼운 수학 연산을 할 때
math 모듈
상수
| |
기본 연산
| |
로그/지수
| |
삼각함수
| |
팩토리얼, GCD, LCM
| |
특수 함수
| |
statistics 모듈
평균
| |
중앙값
| |
최빈값
| |
분산과 표준편차
| |
분위수 (Python 3.8+)
| |
상관계수와 선형회귀 (Python 3.10+)
| |
예제: 기본 통계 분석
| |
자주 하는 실수
1. 부동소수점 비교
| |
2. 정수 나눗셈
| |
한눈에 정리
| 카테고리 | math | statistics |
|---|---|---|
| 기본 연산 | sqrt, pow, ceil, floor | - |
| 삼각함수 | sin, cos, tan, radians | - |
| 로그 | log, log10, exp | - |
| 중심경향 | - | mean, median, mode |
| 분산 | - | stdev, variance |
| 조합 | comb, perm, factorial | - |
![Featured image of post [Python Cheatsheet] 46. math & statistics - 수학/통계 함수](/post/python-cheatsheet/math-statistics-functions-guide-essential-formulas-examples/wordcloud_hu_683b39bd422a3d5d.png)
![[Python Cheatsheet] 44. Database - sqlite3/ORM 기본 패턴](/post/python-cheatsheet/simple-sqlite-database-guide-for-fast-sql-crud-class-methods/wordcloud_hu_ad3db062b1d07b55.png)
![[Python Cheatsheet] 45. weakref - 약한 참조와 메모리 관리](/post/python-cheatsheet/weakref-memory-leak-circular-reference-garbage-collection-cache/wordcloud_hu_b263c232b3042b91.png)
![[Python Cheatsheet] 46. math & statistics - 수학/통계 함수](/post/python-cheatsheet/math-statistics-functions-guide-essential-formulas-examples/wordcloud_hu_bed0ef98794d157a.png)
![[Python Cheatsheet] 47. decimal & fractions - 정밀 수치 연산](/post/python-cheatsheet/decimal-fraction-precision-finance-scientific-guide/wordcloud_hu_cfd96728ef91be24.png)
![[Python Cheatsheet] 48. random - 난수 생성과 무작위 선택](/post/python-cheatsheet/random-module-guide-efficient-random-number-generation-examples/wordcloud_hu_9cf9ac9b3973818e.png)
![[Python Cheatsheet] 49. uuid - 고유 식별자 생성](/post/python-cheatsheet/unique-id-generation-uuid-module-guide/wordcloud_hu_876fcc3ecaf27d7e.png)
![[Python Cheatsheet] 00. Overview - 사용법/커리큘럼/로드맵](/post/python-cheatsheet/roadmap-overview-essential-guide-for-efficient-curriculum/wordcloud_hu_89de6aae6dbda848.png)
![[Python Cheatsheet] 09. Decorators - 함수/클래스 데코레이터](/post/python-cheatsheet/guide-decorators-functions-classes-wrapper-examples-reference/wordcloud_hu_5116df45caa4e900.png)
![[Python Cheatsheet] 12. Context Managers - with문/리소스 관리](/post/python-cheatsheet/context-manager-with-resource-management-best-practices-guide/wordcloud_hu_c4127dc6ae73e7db.png)