Note of Python Math

Note of Python Math

math 库是Python 提供的内置数学类函数库,而其中复数类型常用于科学计算,一般计算并不常用,因此math 库不支持复数类型。math 库一共提供4个数学常数和44个函数(包括16个数值表示函数、8个幂对数函数、16个三角对数函数和4个高等特殊函数)。

1. 调用库函数

(1) 导入库函数:import  <库名>

使用库中函数:<库名> . <函数名> (<函数参数>)

(2) 导入库函数:from  <库名>  import * ( *为通配符 )

使用库中函数:<函数名> (<函数参数>

2. math库函数

(1) 4个数学常数


常数


数学表示


说明


pi


π


圆周率(3.141592653589793)


e


e


自然对数(2.718281828459045)


inf



正无穷大


nan


非浮点数标记(Not a Number)

(2) 16个数值表示函数


函数


数学表示


说明


fabs(x)


|x|


返回x的绝对值


fmod(x)


x%y


返回x与y的模


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


x+y+...


浮点数精确求和


ceil(x)

 
向上取整,返回不小于x的最小整数


floor(x)

 
向上取整,返回不大于x的最大整数


factorial(x)


x!


返回x的阶乘


gcd(a,b)


返回a与b的最大公约数,当x为小数或负数时,返回 ValueError


frexp(x)

 
返回(m,e),当x=0时,返回 (0.0 , 0)


ldexp(x,i)

 
返回运算值,frexp(x)的反运算


modf(x)


返回x的小数和整数部分


trunc(x)


返回x的整数部分


copysign(x,y)


|x|*|y|/y


用y的正负号替换x的正负号


isclose(a,b)


比较a与b的相似性,返回True或False


isfinite(x)


当x为无穷大或Nan时返回True;否则返回False


isinf(x)


当x为无穷大时返回True;否则返回False


isnan(x)


当x为Nan时返回True;否则返回False

(3) 8个幂对数函数


函数


数学表示


说明


pow(x,y)

 
返回x的y次幂


exp(x)

 
返回e的x次幂


expml(x)

 
返回e的x次幂减1


sqrt(x)

 
返回x的平方根


log(x [,base])

 
返回x的对数值,只输入x时,base = e


log1p(x)

 
返回1+x的自然对数值


log2(x)

 
返回x的2对数值


log10(x)

 
返回x的10对数值

(4) 16个三角对数函数


函数


数学表示


说明


degrees(x)


角度x的弧度值转角度值


radians(x)


角度x的角度值转弧度值


hypot(x,y)

 
返回坐标 (x,y)到原点的距离


sin(x)


sin x


返回x的正弦函数值,x是弧度值


cos(x)


cos x


返回x的余弦函数值,x是弧度值


tan(x)


tan x


返回x的正切函数值,x是弧度值


asin(x)


arcsin x


返回x的反正弦函数值,x是弧度值


acos(x)


arccos x


返回x的反余弦函数值,x是弧度值


atan(x)


arctan x


返回x的反正切函数值,x是弧度值


atan2(y,x)


arctan y/x


返回y/x的反正切函数值,x是弧度值


sinh(x)


sinh x


返回x的双曲正弦函数值


cosh(x)


cosh x


返回x的双曲余弦函数值


tanh(x)


tanh x


返回x的双曲正切函数值


asinh(x)


arcsinh x


返回x的反双曲正弦函数值


acosh(x)


arccosh x


返回x的反双曲余弦函数值


atanh(x)


arctanh x


返回x的反双曲正切函数值

原文地址:https://www.cnblogs.com/bpf-1024/p/10520476.html

时间: 2024-08-15 03:57:29

Note of Python Math的相关文章

Python 基础学习之: Python math 模块、cmath 模块 区别是 cmath 模块运算的是复数,math 模块运算的是数学运算 Python数学函数列表及解释 Python math 模块提供了许多对浮点数的数学运算函数。 Python cmath 模块包含了一些用于复数运算的函数

Python math 模块.cmath 模块 Python 中数学运算常用的函数基本都在 math 模块.cmath 模块中. Python math 模块提供了许多对浮点数的数学运算函数. Python cmath 模块包含了一些用于复数运算的函数. cmath 模块的函数跟 math 模块函数基本一致,区别是 cmath 模块运算的是复数,math 模块运算的是数学运算. 要使用 math 或 cmath 函数必须先导入: import math 查看 math 查看包中的内容: impo

python math模块

1.math简介 >>> import math >>>dir(math)           #这句可查看所有函数名列表 ['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'ex

Python math库和random库

1.math库 1 >>> from math import * 2 >>> 2*pi 3 6.283185307179586 4 >>> e 5 2.718281828459045 6 >>> ceil(2.3) 7 3 8 >>> floor(2.3) 9 2 10 >>> pow(2,3) 11 8.0 12 >>> log(e) 13 1.0 14 >>>

note on python

iterator Behind the scenes, the for statement calls iter() on the container object. The function returns an iterator object that defines the method __next__() which accesses elements in the container one at a time. When there are no more elements, __

python math

dir(math) ['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fm

python内置math模块知识点

math模块实现了许多对浮点数的数学运算函数. 这些函数一般是对平台 C 库中同名函数的简单封装, 所以一般情况下, 不同平台下计算的结果可能稍微地有所不同, 有时候甚至有很大出入 Python Math 函数  必须 import math 功能说明 指令 範例 返回 x 的反余弦 math.acos(x) 返回 x 的反双曲余弦 math.acosh(x) 返回 x 的反正弦 math.asin(x) 返回 x 的反双曲正弦 math.asinh(x) 返回 x 的反正切 math.atan

[学习笔记] Python标准库简明教程 [转]

1 操作系统接口 os 模块提供了一系列与系统交互的模块: >>> os.getcwd() # Return the current working directory '/home/minix/Documents/Note/Programming/python/lib1' >>> os.chdir('~/python') # Change current working directory Traceback (most recent call last): File

Python模块搜索及模块安装

[import模块] 和C中的#include不同,Python中的import语句并不是简单的把一个文件插入另外一个文件. 导入其实是运行时的运算,程序第一次导入指定文件时,会执行以下步骤, 1. 找到模块文件 2. 编译成位码 3. 执行模块中的代码来创建所定义的模块 并生成.pyc字节码文件,这三个步骤只在程序执行时,模块第一次导入时会进行.之后导入相同的模块时,会跳过这三个步骤,而只提取内存中已加载的模块对象,速度要快的多. NOTE: 1. Python把已加载的模块放在内置的sys.

使用gdb调试Python进程

http://www.cnblogs.com/dkblog/category/287362.html https://wiki.python.org/moin/DebuggingWithGdb There are types of bugs that are difficult to debug from within Python: segfaults (not uncaught Python exceptions) hung processes (in cases where you can