社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

Python数学计算的一些高频操作

量化研究方法 • 4 年前 • 484 次点击  
转自 | pythonic生物人

'{:.ne}'.format()科学计数法

如未指定精度n,则用小数点之后 6 位精度。

'{:.n%}'.format()取百分比

n指定精度。

math.ceil()向上取整

ceil:在英文中,有「天花板」的意思,在上面,所以,此函数是向上取整。

math.floor()向下取整

同样,floor在英文中有地板的意思,在下面,所以,此函数是向下取整。

round()四舍五入

math.modf()取小数、取整数部分

int()取整数

math.fabs()取绝对值

math.gcd()取两个数最大公约数

math.sqrt()开平方

math.pi取圆周率派

math.e取常数e

math.exp()取e的n次方

math.pow(x, y)取x的y次方

math.log2()取以2为底的对数

math.log10()取以10为底的对数

math.log(x, y)

三角函数

  • math.sin()取正弦值

  • math.cos()取余弦值

  • math.tan()取正切值

反三角函数

  • math.acos()取反余弦值

  • math.asin()取反正弦值

  • math.atan()取反正切值


双曲函数

  • math.cosh()取双曲余弦值

  • math.sinh()取双曲正弦值

  • math.tanh()取双曲正切值

  • math.acosh()取反双曲余弦值

  • math.asinh()取反双曲正弦值

  • math.atanh()取反双曲正切值

cmath操作复数

Reference

https://docs.python.org/zh-cn/3/library/string.html#format-specification-mini-language
https://docs.python.org/zh-cn/3/library/math.html?highlight=math#module-math
https://docs.python.org/zh-cn/3/library/cmath.html?highlight=math#module-cmath

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/119286