Python数学模块

在程序开发的时候,可能不仅仅需要加减乘除这样的简单运算,还需要乘方、开方、取绝对值等等这样的复杂运算。这一篇文章将要介绍Python的数学内置模块math,这个内置模块能够解决常见的绝大部分数学运算。

常用的math方法

math.e

自然常数e

math.pi

圆周率pi

math.exp(x)

返回e的x次方

math.expm1(x)

返回e的x次方减1

math.log(x[, base])

返回x的以base为底的对数,base默认为e

math.log10(x)

返回x的以10为底的对数 相当于 math.log(x,10)

math.pow(x, y)

返回x的y次方

math.sqrt(x)

返回x的平方根

math.ceil(x)

返回不小于x的整数

math.floor(x)

返回不大于x的整数

math.trunc(x)

返回x的整数部分

math.modf(x)

返回x的小数和整数 元组形式

math.fabs(x)

返回x的绝对值

math.fmod(x, y)

返回x%y(取余)

math.fsum([x, y, ...])

返回无损精度的和

math.factorial(x)

返回x的阶乘 阶乘就是 1*2*3...*(x-2)*(x-1)*x

math.isinf(x)

若x为无穷大,返回True;否则,返回False

math.isnan(x)

若x不是数字,返回True;否则,返回False

math.hypot(x, y)

返回以x和y为直角边的斜边长

math.copysign(x, y)

若y<0,返回-1乘以x的绝对值; 否则,返回x的绝对值

math.frexp(x)

返回m和i,满足m乘以2的i次方

math.ldexp(m, i)

返回m乘以2的i次方

math.sin(x)

返回x(弧度)的三角正弦值

math.asin(x)

返回x的反三角正弦值

math.cos(x)

返回x(弧度)的三角余弦值

math.acos(x)

返回x的反三角余弦值

math.tan(x)

返回x(弧度)的三角正切值

math.atan(x)

返回x的反三角正切值

math.atan2(x, y)

返回x/y的反三角正切值

math.sinh(x)

返回x的双曲正弦函数

math.asinh(x)

返回x的反双曲正弦函数

math.cosh(x)

返回x的双曲余弦函数

math.acosh(x)

返回x的反双曲余弦函数

math.tanh(x)

返回x的双曲正切函数

math.atanh(x)

返回x的反双曲正切函数

math.erf(x)

返回x的误差函数

math.erfc(x)

返回x的余误差函数

math.gamma(x)

返回x的伽玛函数

math.lgamma(x)

返回x的绝对值的自然对数的伽玛函数

打印了部分例子

>>> import math>>> >>> math.e2.718281828459045>>> math.pi3.141592653589793>>> math.exp(3)20.085536923187668>>> math.expm1(3)19.085536923187668>>> math.expm1(4)53.598150033144236>>> math.log(math.e)1.0>>> math.pow(3,2)9.0>>> math.pow(2,3)8.0>>> math.sqrt(8)2.8284271247461903>>> math.sqrt(9)3.0>>> math.ceil(5.1)6>>> math.ceil(5)5>>> math.ceil(5.0)5>>> math.floor(5.1)5>>> math.floor(5.9)5>>> math.trunc(5.1)5>>> math.trunc(7.1)7>>> math.modf(7.1)(0.09999999999999964, 7.0)>>> >>> math.fabs(10)10.0>>> math.fabs(-10)10.0>>> math.factorial(5)120>>> math.factorial(6)720>>> 

math模块下其他方法

>>> help(math)Help on built-in module math:NAME mathDESCRIPTION This module is always available. It provides access to the mathematical functions defined by the C standard.FUNCTIONS acos(x, /) Return the arc cosine (measured in radians) of x.  acosh(x, /) Return the inverse hyperbolic cosine of x.  asin(x, /) Return the arc sine (measured in radians) of x.  asinh(x, /) Return the inverse hyperbolic sine of x.  atan(x, /) Return the arc tangent (measured in radians) of x.  atan2(y, x, /) Return the arc tangent (measured in radians) of y/x.  Unlike atan(y/x), the signs of both x and y are considered.  atanh(x, /) Return the inverse hyperbolic tangent of x.  ceil(x, /) Return the ceiling of x as an Integral.  This is the smallest integer >= x.  copysign(x, y, /) Return a float with the magnitude (absolute value) of x but the sign of y.  On platforms that support signed zeros, copysign(1.0, -0.0) returns -1.0.  cos(x, /) Return the cosine of x (measured in radians).  cosh(x, /) Return the hyperbolic cosine of x.  degrees(x, /) Convert angle x from radians to degrees.  erf(x, /) Error function at x.  erfc(x, /) Complementary error function at x.  exp(x, /) Return e raised to the power of x.  expm1(x, /) Return exp(x)-1.  This function avoids the loss of precision involved in the direct evaluation of exp(x)-1 for small x.  fabs(x, /) Return the absolute value of the float x.  factorial(x, /) Find x!.  Raise a ValueError if x is negative or non-integral.  floor(x, /) Return the floor of x as an Integral.  This is the largest integer <= x.  fmod(x, y, /) Return fmod(x, y), according to platform C.  x % y may differ.  frexp(x, /) Return the mantissa and exponent of x, as pair (m, e).  m is a float and e is an int, such that x = m * 2.**e. If x is 0, m and e are both 0. Else 0.5 <= abs(m) < 1.0.  fsum(seq, /) Return an accurate floating point sum of values in the iterable seq.  Assumes IEEE-754 floating point arithmetic.  gamma(x, /) Gamma function at x.  gcd(x, y, /) greatest common divisor of x and y  hypot(x, y, /) Return the Euclidean distance, sqrt(x*x + y*y).  isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0) Determine whether two floating point numbers are close in value.  rel_tol maximum difference for being considered "close

python 怎么取对数_重新开始学习Python 第二十八天 Python 数学模块相关推荐

  1. python 怎么取对数_概率矩阵分解(PMF)及MovieLens上的Python代码

    首先对Probabilistic Matrix Factorization这篇论文的核心公式进行讲解和推导:然后用Python代码在Movielens数据集上进行测试实验. 一. 背景知识 文中作者提 ...

  2. 用python爬取网站_「自如网」关于用python爬取自如网信息的价格问题(已解决) - seo实验室...

    自如网 ###这是一篇求助文,我能获取图片并变成字符串,但是无法获取位移量### 前两坛突发奇想想要爬取自如网的租房数据,本来以为能够请求+美丽+ re能全部搞定,没想到这个网站的反爬机制有点让我搞不 ...

  3. python数组取对数_关于python:取列的对数

    我对编程非常陌生(在python中),我想创建一个新变量,该变量是列的对数(来自导入的excel文件). 我尝试过从该站点尝试不同的解决方案,但始终出现错误. 我最新的错误是AttributeErro ...

  4. python 数组合并排重_并排深度学习:Julia vs Python

    python 数组合并排重 Julia could possibly be the biggest threat to Python. For a variety of applications, J ...

  5. python查看数据大小_科多大数据带你看Python可以列为最值得学习的编程语言

    原标题:科多大数据带你看Python可以列为最值得学习的编程语言 不知道从什么时候开始,这句话开始流行.不过也从侧面反映出 Python 语言的特点:简单.高效. 从近期代表技术趋势的业界报告以及编程 ...

  6. python爬取学籍_仝卓学籍造假微博道歉,用Python抓取微博的评论看看群众都说什么...

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 欢迎关注小编,除了分享技术文章之外还有很多福利,私信学习资料可以领取包括不 ...

  7. 回归分析什么时候取对数_技术派|SPSS数据分析心得小结及心得分享!必备收藏...

    作者:徐定德 来源:经管之家,欢迎转载,欢迎分享. 学习数据分析之spss分析工具,可真的不是一般的功夫,真的要很认真和很细心才能做得好spss.下面我来和大家分享一下关于SPSS数据分析心得小结,希 ...

  8. 如何用python爬取数据_入门用Python进行Web爬取数据:为数据科学项目提取数据的有效方法...

    作者|LAKSHAY ARORA 编译|Flin 来源|analyticsvidhya 总览 Web抓取是一种从网站提取数据的高效方法(取决于网站的规定) 了解如何使用流行的BeautifulSoup ...

  9. python爬取文字和图片_Python学习第七天之爬虫的学习与使用(爬取文字、图片、 视频)...

    [toc] 一.爬虫记得基本方法 1.1 爬虫概述 ​ 网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本. ...

最新文章

  1. labview 随笔记录
  2. 湖南大学计算机与通信学院研究生,湖南大学计算机与通信学院2010年硕士研究生招生学科...
  3. mysql根据已有表创建新表_SQL根据现有表新建一张表
  4. QML笔记-使用connect界面数据交互(qml中Designer使用)
  5. LINUX考证优惠信息转发(图)
  6. 怎样才能有德国煤矿那样严密的安全网?
  7. 颠覆智能手机的下一代设备已出现?
  8. 软件物料清单 (SBOM):从透明度理念到代码落地
  9. 解决springmvc加载JS,CSS等文件问题【转】
  10. 三维曲面图像绘制(光照控制)
  11. PHP代码更新后画面不更新,为什么我的PHP代码不能更新SQL
  12. nyoj(简单数学)Oh, my Paper!
  13. java swing获得焦点_Java Swing TextArea 滚动条并获取焦点
  14. vue.js中修饰符.stop的用法。
  15. 计算机导航窗格有两个c盘,电脑怎么格式化所有盘只留系统
  16. Vue中使用wangEditor实现自定义上传图片和视频
  17. C++实现图像转字符画
  18. cpu功耗排行_目前较低功耗的intel系cpu求推荐?
  19. 专业程序员开发-老狼孩插件懒人精灵版
  20. 12. 深度学习三巨头

热门文章

  1. PAT 1032 (未完成)
  2. 初级程序员面试不靠谱指南(二)
  3. python到底有什么用-Python中的闭包到底有什么用
  4. Linux之32/64位int、char、int*、char*与空结构体大小
  5. C++ ofstream/ifstream读写文件demo
  6. android之Canvas绘制图片
  7. Web服务器基础详解
  8. ubuntu防火墙问题
  9. 站点简介(欢迎大家踊跃参与本站站点的建设,谢谢)
  10. easyui crud java_轻松学习jQuery插件EasyUI EasyUI创建CRUD应用