python 数学符号读法大全_math_数字与数学 | Numeric Mathematical_Python_参考手册_非常教程...
math
該模塊始終可用。它提供對由C標準定義的數學函數的訪問。
這些功能不能用于復數; cmath如果您需要支持復雜數字,請使用模塊中相同名稱的功能。支持復數的功能和不支持的功能之間的區別是由于大多數用戶不想學習理解復數所需的太多數學。接收一個異常而不是一個復雜的結果,可以更早地檢測出用作參數的意外復數,這樣程序員就可以確定首先產生的方式和原因。
以下功能由該模塊提供。除非另外明確指出,否則所有返回值都是浮點數。
1.數論和表示函數
math.ceil(x)
返回x的上限作為float,最小的整數值大于或等于x。
math.copysign(x, y)
用y的符號返回x。在支持帶符號的零的平臺上,返回-1.0。copysign(1.0, -0.0)
2.6版本中的新功能。
math.fabs(x)
返回x的絕對值。
math.factorial(x)
返回x階乘。ValueError如果x不是整數或者是負數,則引發。
2.6版本中的新功能。
math.floor(x)
將x的底部作為浮點數返回,最大的整數值小于或等于x。
math.fmod(x, y)
返回fmod(x, y),由平臺C庫定義。請注意,Python表達式x % y可能不會返回相同的結果。C標準的意圖fmod(x, y)是精確地(數學上的;以無限的精度)等于x - n*y某個整數n,使得結果的符號與x和幅度小于abs(y)。Python的x % y返回結果會帶有y的符號,并且對于float參數可能不是完全可計算的。例如,fmod(-1e-100, 1e100)是的-1e-100,但Python的結果-1e-100 % 1e100是1e100-1e-100,它不能完全表示為一個浮點數,并且令人驚訝1e100。出于這個原因,功能fmod()在使用浮點數時一般首選,而x % y在使用整數時首選Python 。
math.frexp(x)
返回x的尾數和指數作為一對(m, e)。m是一個浮點數,e是一個整數x == m * 2**e。如果x為零,則返回(0.0, 0),否則返回0.5 <= abs(m) < 1。這用于以便攜方式“分離”浮點的內部表示。
math.fsum(iterable)
在迭代器中返回一個精確的浮點和值。通過跟蹤多個中間部分和來避免精度損失:
>>> sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
0.9999999999999999
>>> fsum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
1.0
該算法的精度取決于IEEE-754算術保證和舍入模式為半均勻的典型情況。在一些非Windows版本中,底層C庫使用擴展精度加法,偶爾會使中間和加倍,導致它在最低有效位中關閉。
有關進一步的討論和兩種替代方法,請參閱ASPN食譜配方以獲得準確的浮點總和。
2.6版本中的新功能。
math.isinf(x)
檢查float x是正值還是負值無窮大。
2.6版本中的新功能。
math.isnan(x)
檢查float x是否是NaN(不是數字)。有關NaN的更多信息,請參閱IEEE 754標準。
2.6版本中的新功能。
math.ldexp(x, i)
返回x * (2**i)。這基本上是函數的反函數frexp()。
math.modf(x)
返回x的小數部分和整數部分。兩個結果都帶有x的符號并且是浮點數。
math.trunc(x)
將截斷的Real值x返回Integral(通常是一個長整數)。使用該__trunc__方法。
2.6版本中的新功能。
注意,frexp()和modf()具有比它們的C當量的不同調用/返回的模式:它們采取單參數和返回的一對值,而不是通過“輸出參數”返回其第二返回值(有在Python沒有這樣的事情)。
對于ceil(),floor()和modf()功能,請注意,所有的足夠大的幅度的浮點數字是準確的整數。Python浮點運算的精度通常不超過53位(與平臺C的雙精度類型相同),在這種情況下,任何有必要的浮點數xabs(x) >= 2**52都沒有小數位。
2.功率和對數函數
math.exp(x)
返回e**x。
math.expm1(x)
返回e**x - 1。對于小浮點數x,減法exp(x) - 1可導致精度的顯著損失; 該expm1()函數提供了一種以完全精確的方式計算此數量的方法:
>>> from math import exp, expm1
>>> exp(1e-5) - 1 # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1(1e-5) # result accurate to full precision
1.0000050000166668e-05
2.7版本的新功能。
math.log(x[, base])
用一個參數,返回x的自然對數(以e為底)。
用兩個參數,將x的對數返回給定的基數,計算為log(x)/log(base)。
在版本2.3中更改:添加了基本參數。
math.log1p(x)
返回1 + x的自然對數(基數e)。計算結果的方式對于接近零的x是準確的。
2.6版本中的新功能。
math.log10(x)
返回x的基數為10的對數。這通常比......更準確log(x, 10)。
math.pow(x, y)
返回x提升到權力y。例外情況應盡可能遵循C99標準的附件'F'。特別是,pow(1.0, x)和pow(x, 0.0)總是返回1.0,即使x是零或為NaN。如果兩個x和y是有限的,x是負的,而y不是整數然后pow(x, y)是未定義的,并提高ValueError。
與內置**運算符不同,math.pow()將其兩個參數都轉換為類型float。使用**或內置pow()函數來計算精確的整數冪。
在版本2.6中更改:結果1**nan和nan**0未定義。
math.sqrt(x)
返回x的平方根。
3.三角函數
math.acos(x)
返回x的反余弦,單位為弧度。
math.asin(x)
以弧度返回x的反正弦。
math.atan(x)
以弧度返回x的反正切。
math.atan2(y, x)
返回atan(y / x),以弧度表示。結果在-pi和之間pi。從原點到點的平面中的矢量(x, y)與正X軸形成此角度。重點atan2()是兩個輸入的符號都是已知的,所以它可以計算角度的正確象限。例如,atan(1)并且atan2(1, 1)都是pi/4,但atan2(-1, -1)就是-3*pi/4。
math.cos(x)
返回x弧度的余弦。
math.hypot(x, y)
返回歐幾里得規范,sqrt(x*x + y*y)。這是從原點到點的矢量長度(x, y)。
math.sin(x)
返回x弧度的正弦值。
math.tan(x)
返回x弧度的切線。
4.角度轉換
math.degrees(x)
將角度x從弧度轉換為度數。
math.radians(x)
將角度x從度數轉換為弧度。
5.雙曲函數
math.acosh(x)
返回x的反雙曲余弦。
2.6版本中的新功能。
math.asinh(x)
返回x的反雙曲正弦。
2.6版本中的新功能。
math.atanh(x)
返回x的反雙曲正切。
2.6版本中的新功能。
math.cosh(x)
返回x的雙曲余弦。
math.sinh(x)
返回x的雙曲正弦。
math.tanh(x)
Return the hyperbolic tangent of x.
6. Special functions
math.erf(x)
Return the error function at x.
New in version 2.7.
math.erfc(x)
Return the complementary error function at x.
New in version 2.7.
math.gamma(x)
Return the Gamma function at x.
New in version 2.7.
math.lgamma(x)
Return the natural logarithm of the absolute value of the Gamma function at x.
New in version 2.7.
7. Constants
math.pi
The mathematical constant π = 3.141592..., to available precision.
math.e
The mathematical constant e = 2.718281..., to available precision.
CPython implementation detail: The math module consists mostly of thin wrappers around the platform C math library functions. Behavior in exceptional cases follows Annex F of the C99 standard where appropriate. The current implementation will raise ValueError for invalid operations like sqrt(-1.0) or log(0.0) (where C99 Annex F recommends signaling invalid operation or divide-by-zero), and OverflowError for results that overflow (for example, exp(1000.0)). A NaN will not be returned from any of the functions above unless one or more of the input arguments was a NaN; in that case, most functions will return a NaN, but (again following C99 Annex F) there are some exceptions to this rule, for example pow(float('nan'), 0.0) or hypot(float('nan'), float('inf')).
Note that Python makes no effort to distinguish signaling NaNs from quiet NaNs, and behavior for signaling NaNs remains unspecified. Typical behavior is to treat all NaNs as though they were quiet.
Changed in version 2.6: Behavior in special cases now aims to follow C99 Annex F. In earlier versions of Python the behavior in special cases was loosely specified.
See also
Module cmath Complex number versions of many of these functions.
? 2001–2017 Python Software Foundation
Licensed under the PSF License.
總結
以上是生活随笔為你收集整理的python 数学符号读法大全_math_数字与数学 | Numeric Mathematical_Python_参考手册_非常教程...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java猜字母讲解_JAVA语言中的经典
- 下一篇: 怎么看java中ide_如何在eclip