【NB】Python math 模块与 cmath 模块

浅殇酱   ·   发表于 2021-3-19   ·   编程代码

Python math 模块提供了许多对浮点数的数学运算函数。
Python cmath 模块包含了一些用于复数运算的函数。
cmath 模块的函数跟 math 模块函数基本一致,区别是 cmath 模块运算的是复数,math 模块运算的是数学运算。
20 Reply   |  Until 2021-3-20 | 4264 View

tlyl6818
发表于 2021-3-19

要使用 math 或 cmath 函数必须先导入:
import math

评论列表

  • 加载数据中...

编写评论内容

2723147094
发表于 2021-3-19

查看 math 查看包中的内容:

评论列表

  • 加载数据中...

编写评论内容

asdfkns
发表于 2021-3-19

>>> import math
>>> dir(math)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc']
>>>

评论列表

  • 加载数据中...

编写评论内容

syf1313113
发表于 2021-3-19

各个函数解析:

评论列表

  • 加载数据中...

编写评论内容

裕伤
发表于 2021-3-19

Python 复数的支持和 cmath 模块应用

评论列表

  • 加载数据中...

编写评论内容

83344617
发表于 2021-3-19

Python 提供对于复数运算的支持,复数在 Python 中的表达式为 C==c.real+c.imag*j,复数 C 由他的实部和虚部组成。

评论列表

  • 加载数据中...

编写评论内容

inkxx888
发表于 2021-3-19

对于复数,Python 支持它的加减乘除运算,同时提供了 cmath 模块对其他复杂运算进行支持。cmath 模块和 Python 中的 math 模块对应, math提供对于实数的支持, 在这里主要讨论 cmath 模块中的几个函数的用法。

评论列表

  • 加载数据中...

编写评论内容

143242
发表于 2021-3-19

查看 cmath 查看包中的内容

评论列表

  • 加载数据中...

编写评论内容

menglicl
发表于 2021-3-19

>>> import cmath
>>> dir(cmath)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh', 'cos', 'cosh', 'e', 'exp', 'inf', 'infj', 'isclose', 'isfinite', 'isinf', 'isnan', 'log', 'log10', 'nan', 'nanj', 'phase', 'pi', 'polar', 'rect', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau']
>>>

评论列表

  • 加载数据中...

编写评论内容

1018476364
发表于 2021-3-19

1.极坐标和笛卡尔坐标表示的转换。
C==c.real+c.imag*j 的复数表示方法为复数的笛卡尔表示法, cmath 模块中的 polar() 方法和 rect() 方法可以对复数进行极坐标表示和笛卡尔表示方法的转换。

评论列表

  • 加载数据中...

编写评论内容
LoginCan Publish Content