python調(diào)用伽馬函數(shù) 函數(shù)的調(diào)用Python

Python--math庫

Python math 庫提供許多對浮點(diǎn)數(shù)的數(shù)學(xué)運(yùn)算函數(shù),math模塊不支持復(fù)數(shù)運(yùn)算,若需計算復(fù)數(shù),可使用cmath模塊(本文不贅述)。

創(chuàng)新互聯(lián)建站專注于企業(yè)成都營銷網(wǎng)站建設(shè)、網(wǎng)站重做改版、達(dá)州網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5高端網(wǎng)站建設(shè)商城建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)公司、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為達(dá)州等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

使用dir函數(shù),查看math庫中包含的所有內(nèi)容:

1) math.pi????# 圓周率π

2) math.e????#自然對數(shù)底數(shù)

3) math.inf? ? #正無窮大∞,-math.inf? ? #負(fù)無窮大-∞

4) math.nan? ? #非浮點(diǎn)數(shù)標(biāo)記,NaN(not a number)

1) math.fabs(x)? ? #表示X值的絕對值

2) math.fmod(x,y)? ? #表示x/y的余數(shù),結(jié)果為浮點(diǎn)數(shù)

3) math.fsum([x,y,z])? ? #對括號內(nèi)每個元素求和,其值為浮點(diǎn)數(shù)

4) math.ceil(x)? ? #向上取整,返回不小于x的最小整數(shù)

5)math.floor(x)? ? #向下取整,返回不大于x的最大整數(shù)

6) math.factorial(x)? ? #表示X的階乘,其中X值必須為整型,否則報錯

7) math.gcd(a,b)? ? #表示a,b的最大公約數(shù)

8)? math.frexp(x)? ? ? #x = i *2^j,返回(i,j)

9) math.ldexp(x,i)? ? #返回x*2^i的運(yùn)算值,為math.frexp(x)函數(shù)的反運(yùn)算

10) math.modf(x)? ? #表示x的小數(shù)和整數(shù)部分

11) math.trunc(x)? ? #表示x值的整數(shù)部分

12) math.copysign(x,y)? ? #表示用數(shù)值y的正負(fù)號,替換x值的正負(fù)號

13) math.isclose(a,b,rel_tol =x,abs_tol = y)? ? #表示a,b的相似性,真值返回True,否則False;rel_tol是相對公差:表示a,b之間允許的最大差值,abs_tol是最小絕對公差,對比較接近于0有用,abs_tol必須至少為0。

14) math.isfinite(x)? ? #表示當(dāng)x不為無窮大時,返回True,否則返回False

15) math.isinf(x)? ? #當(dāng)x為±∞時,返回True,否則返回False

16) math.isnan(x)? ? #當(dāng)x是NaN,返回True,否則返回False

1) math.pow(x,y)? ? #表示x的y次冪

2) math.exp(x)? ? #表示e的x次冪

3) math.expm1(x)? ? #表示e的x次冪減1

4) math.sqrt(x)? ? #表示x的平方根

5) math.log(x,base)? ? #表示x的對數(shù)值,僅輸入x值時,表示ln(x)函數(shù)

6) math.log1p(x)? ? #表示1+x的自然對數(shù)值

7) math.log2(x)? ? #表示以2為底的x對數(shù)值

8) math.log10(x)? ? #表示以10為底的x的對數(shù)值

1) math.degrees(x)? ? #表示弧度值轉(zhuǎn)角度值

2) math.radians(x)? ? #表示角度值轉(zhuǎn)弧度值

3) math.hypot(x,y)? ? #表示(x,y)坐標(biāo)到原點(diǎn)(0,0)的距離

4) math.sin(x)? ? #表示x的正弦函數(shù)值

5) math.cos(x)? ? #表示x的余弦函數(shù)值

6) math.tan(x)? ? #表示x的正切函數(shù)值

7)math.asin(x)? ? #表示x的反正弦函數(shù)值

8)?math.acos(x)? ? #表示x的反余弦函數(shù)值

9)?math.atan(x)? ? #表示x的反正切函數(shù)值

10) math.atan2(y,x)? ? #表示y/x的反正切函數(shù)值

11) math.sinh(x)? ? #表示x的雙曲正弦函數(shù)值

12) math.cosh(x)? ? #表示x的雙曲余弦函數(shù)值

13) math.tanh(x)? ? #表示x的雙曲正切函數(shù)值

14) math.asinh(x)? ? #表示x的反雙曲正弦函數(shù)值

15) math.acosh(x)? ? #表示x的反雙曲余弦函數(shù)值

16) math.atanh(x)? ? #表示x的反雙曲正切函數(shù)值

1)math.erf(x)? ? #高斯誤差函數(shù)

2) math.erfc(x)? ? #余補(bǔ)高斯誤差函數(shù)

3) math.gamma(x)? ? #伽馬函數(shù)(歐拉第二積分函數(shù))

4) math.lgamma(x)? ? #伽馬函數(shù)的自然對數(shù)

python3的sympy

print(“字符串”),5/2和5//2的結(jié)果是不同的5/2為2.5,5//2為2.

python2需要導(dǎo)入from_future_import division執(zhí)行普通的除法。

1/2和1//2的結(jié)果0.5和0.

%號為取模運(yùn)算。

乘方運(yùn)算為2**3,-2**3和-(2**3)是等價的。

from sympy import*導(dǎo)入庫

x,y,z=symbols('x y z'),定義變量

init_printing(use_unicode=True)設(shè)置打印方式。

python的內(nèi)部常量有pi,

函數(shù)simplify,simplify(sin(x)**2 + cos(x)**2)化簡結(jié)果為1,

simplify((x**3 + x**2 - x - 1)/(x**2 + 2*x + 1))化簡結(jié)果為x-1?;嗁ゑR函數(shù)。simplify(gamma(x)/gamma(x - 2))得(x-2)(x-1)。

expand((x + 1)**2)展開多項(xiàng)式。

expand((x + 1)*(x - 2) - (x - 1)*x)

因式分解。factor(x**2*z + 4*x*y*z + 4*y**2*z)得到z*(x + 2*y)**2

from_future_import division

x,y,z,t=symbols('x y z t')定義變量,

k, m, n = symbols('k m n', integer=True)定義三個整數(shù)變量。

f, g, h = symbols('f g h', cls=Function)定義的類型為函數(shù)。

factor_list(x**2*z + 4*x*y*z + 4*y**2*z)得到一個列表,表示因式的冪,(1, [(z, 1), (x + 2*y, 2)])

expand((cos(x) + sin(x))**2)展開多項(xiàng)式。

expr = x*y + x - 3 + 2*x**2 - z*x**2 + x**3,collected_expr = collect(expr, x)將x合并。將x元素按階次整合。

collected_expr.coeff(x, 2)直接取出變量collected_expr的x的二次冪的系數(shù)。

cancel()is more efficient thanfactor().

cancel((x**2 + 2*x + 1)/(x**2 + x))

,expr = (x*y**2 - 2*x*y*z + x*z**2 + y**2 - 2*y*z + z**2)/(x**2 - 1),cancel(expr)

expr = (4*x**3 + 21*x**2 + 10*x + 12)/(x**4 + 5*x**3 + 5*x**2 + 4*x),apart(expr)

asin(1)

trigsimp(sin(x)**2 + cos(x)**2)三角函數(shù)表達(dá)式化簡,

trigsimp(sin(x)**4 - 2*cos(x)**2*sin(x)**2 + cos(x)**4)

trigsimp(sin(x)*tan(x)/sec(x))

trigsimp(cosh(x)**2 + sinh(x)**2)雙曲函數(shù)。

三角函數(shù)展開,expand_trig(sin(x + y)),acos(x),cos(acos(x)),expand_trig(tan(2*x))

x, y = symbols('x y', positive=True)正數(shù),a, b = symbols('a b', real=True)實(shí)數(shù),z, t, c = symbols('z t c')定義變量的方法。

sqrt(x) == x**Rational(1, 2)判斷是否相等。

powsimp(x**a*x**b)冪函數(shù)的乘法,不同冪的乘法,必須先定義a和b。powsimp(x**a*y**a)相同冪的乘法。

powsimp(t**c*z**c),注意,powsimp()refuses to do the simplification if it is not valid.

powsimp(t**c*z**c, force=True)這樣的話就可以得到化簡過的式子。聲明強(qiáng)制進(jìn)行化簡。

(z*t)**2,sqrt(x*y)

第一個展開expand_power_exp(x**(a + b)),expand_power_base((x*y)**a)展開,

expand_power_base((z*t)**c, force=True)強(qiáng)制展開。

powdenest((x**a)**b),powdenest((z**a)**b),powdenest((z**a)**b, force=True)

ln(x),x, y ,z= symbols('x y z', positive=True),n = symbols('n', real=True),

expand_log(log(x*y))展開為log(x) + log(y),但是python3沒有。這是因?yàn)樾枰獙定義為positive。這是必須的,否則不會被展開。expand_log(log(x/y)),expand_log(log(x**n))

As withpowsimp()andpowdenest(),expand_log()has aforceoption that can be used to ignore assumptions。

expand_log(log(z**2), force=True),強(qiáng)制展開。

logcombine(log(x) + log(y)),logcombine(n*log(x)),logcombine(n*log(z), force=True)。

factorial(n)階乘,binomial(n, k)等于c(n,k),gamma(z)伽馬函數(shù)。

hyper([1, 2], [3], z),

tan(x).rewrite(sin)得到用正弦表示的正切。factorial(x).rewrite(gamma)用伽馬函數(shù)重寫階乘。

expand_func(gamma(x + 3))得到,x*(x + 1)*(x + 2)*gamma(x),

hyperexpand(hyper([1, 1], [2], z)),

combsimp(factorial(n)/factorial(n - 3))化簡,combsimp(binomial(n+1, k+1)/binomial(n, k))化簡。combsimp(gamma(x)*gamma(1 - x))

自定義函數(shù)

def list_to_frac(l):

expr = Integer(0)

for i in reversed(l[1:]):

expr += i

expr = 1/expr

return l[0] + expr

list_to_frac([x, y, z])結(jié)果為x + 1/z,這個結(jié)果是錯誤的。

syms = symbols('a0:5'),定義syms,得到的結(jié)果為(a0, a1, a2, a3, a4)。

這樣也可以a0, a1, a2, a3, a4 = syms, 可能是我的操作錯誤 。發(fā)現(xiàn)python和自動縮進(jìn)有關(guān),所以一定看好自動縮進(jìn)的距離。list_to_frac([1, 2, 3, 4])結(jié)果為43/30。

使用cancel可以將生成的分式化簡,frac = cancel(frac)化簡為一個分?jǐn)?shù)線的分式。

(a0*a1*a2*a3*a4 + a0*a1*a2 + a0*a1*a4 + a0*a3*a4 + a0 + a2*a3*a4 + a2 + a4)/(a1*a2*a3*a4 + a1*a2 + a1*a4 + a3*a4 + 1)

a0, a1, a2, a3, a4 = syms定義a0到a4,frac = apart(frac, a0)可將a0提出來。frac=1/(frac-a0)將a0去掉取倒。frac = apart(frac, a1)提出a1。

help("modules"),模塊的含義,help("modules yourstr")模塊中包含的字符串的意思。,

help("topics"),import os.path + help("os.path"),help("list"),help("open")

# -*- coding: UTF-8 -*-聲明之后就可以在ide中使用中文注釋。

定義

l = list(symbols('a0:5'))定義列表得到[a0, a1, a2, a3, a4]

fromsympyimport*

x,y,z=symbols('x y z')

init_printing(use_unicode=True)

diff(cos(x),x)求導(dǎo)。diff(exp(x**2), x),diff(x**4, x, x, x)和diff(x**4, x, 3)等價。

diff(expr, x, y, 2, z, 4)求出表達(dá)式的y的2階,z的4階,x的1階導(dǎo)數(shù)。和diff(expr, x, y, y, z, 4)等價。expr.diff(x, y, y, z, 4)一步到位。deriv = Derivative(expr, x, y, y, z, 4)求偏導(dǎo)。但是不顯示。之后用deriv.doit()即可顯示

integrate(cos(x), x)積分。定積分integrate(exp(-x), (x, 0, oo))無窮大用2個oo表示。integrate(exp(-x**2-y**2),(x,-oo,oo),(y,-oo,oo))二重積分。print(expr)print的使用。

expr = Integral(log(x)**2, x),expr.doit()積分得到x*log(x)**2 - 2*x*log(x) + 2*x。

integ.doit()和integ = Integral((x**4 + x**2*exp(x) - x**2 - 2*x*exp(x) - 2*x -

exp(x))*exp(x)/((x - 1)**2*(x + 1)**2*(exp(x) + 1)), x)連用。

limit(sin(x)/x,x,0),not-a-number表示nan算不出來,limit(expr, x, oo),,expr = Limit((cos(x) - 1)/x, x, 0),expr.doit()連用。左右極限limit(1/x, x, 0, '+'),limit(1/x, x, 0, '-')。。

Series Expansion級數(shù)展開。expr = exp(sin(x)),expr.series(x, 0, 4)得到1 + x + x**2/2 + O(x**4),,x*O(1)得到O(x),,expr.series(x, 0, 4).removeO()將無窮小移除。exp(x-6).series(x,x0=6),,得到

-5 + (x - 6)**2/2 + (x - 6)**3/6 + (x - 6)**4/24 + (x - 6)**5/120 + x + O((x - 6)**6, (x, 6))最高到5階。

f=Function('f')定義函數(shù)變量和h=Symbol('h')和d2fdx2=f(x).diff(x,2)求2階,,as_finite_diff(dfdx)函數(shù)和as_finite_diff(d2fdx2,[-3*h,-h,2*h]),,x_list=[-3,1,2]和y_list=symbols('a b c')和apply_finite_diff(1,x_list,y_list,0)。

Eq(x, y),,solveset(Eq(x**2, 1), x)解出來x,當(dāng)二式相等。和solveset(Eq(x**2 - 1, 0), x)等價。solveset(x**2 - 1, x)

solveset(x**2 - x, x)解,solveset(x - x, x, domain=S.Reals)解出來定義域。solveset(exp(x), x)? ? # No solution exists解出EmptySet()表示空集。

等式形式linsolve([x + y + z - 1, x + y + 2*z - 3 ], (x, y, z))和矩陣法linsolve(Matrix(([1, 1, 1, 1], [1, 1, 2, 3])), (x, y, z))得到{(-y - 1, y, 2)}

A*x = b 形式,M=Matrix(((1,1,1,1),(1,1,2,3))),system=A,b=M[:,:-1],M[:,-1],linsolve(system,x,y,z),,solveset(x**3 - 6*x**2 + 9*x, x)解多項(xiàng)式。roots(x**3 - 6*x**2 + 9*x, x),得出,{3: 2, 0: 1},有2個3的重根,1個0根。solve([x*y - 1, x - 2], x, y)解出坐標(biāo)。

f, g = symbols('f g', cls=Function)函數(shù)的定義,解微分方程diffeq = Eq(f(x).diff(x, x) - 2*f(x).diff(x) + f(x), sin(x))再和dsolve(diffeq,f(x))結(jié)合。得到Eq(f(x), (C1 + C2*x)*exp(x) + cos(x)/2),dsolve(f(x).diff(x)*(1 - sin(f(x))), f(x))解出來Eq(f(x) + cos(f(x)), C1),,

Matrix([[1,-1],[3,4],[0,2]]),,Matrix([1, 2, 3])列表示。M=Matrix([[1,2,3],[3,2,1]])

N=Matrix([0,1,1])

M*N符合矩陣的乘法。M.shape顯示矩陣的行列數(shù)。

M.row(0)獲取M的第0行。M.col(-1)獲取倒數(shù)第一列。

M.col_del(0)刪掉第1列。M.row_del(1)刪除第二行,序列是從0開始的。M = M.row_insert(1, Matrix([[0, 4]]))插入第二行,,M = M.col_insert(0, Matrix([1, -2]))插入第一列。

M+N矩陣相加,M*N,3*M,M**2,M**-1,N**-1表示求逆。M.T求轉(zhuǎn)置。

eye(3)單位。zeros(2, 3),0矩陣,ones(3, 2)全1,diag(1, 2, 3)對角矩陣。diag(-1, ones(2, 2), Matrix([5, 7, 5]))生成Matrix([

[-1, 0, 0, 0],

[ 0, 1, 1, 0],

[ 0, 1, 1, 0],

[ 0, 0, 0, 5],

[ 0, 0, 0, 7],

[ 0, 0, 0, 5]])矩陣。

Matrix([[1, 0, 1], [2, -1, 3], [4, 3, 2]])

一行一行顯示,,M.det()求行列式。M.rref()矩陣化簡。得到結(jié)果為Matrix([

[1, 0,? 1,? 3],

[0, 1, 2/3, 1/3],

[0, 0,? 0,? 0]]), [0, 1])。

M = Matrix([[1, 2, 3, 0, 0], [4, 10, 0, 0, 1]]),M.nullspace()

Columnspace

M.columnspace()和M = Matrix([[1, 2, 3, 0, 0], [4, 10, 0, 0, 1]])

M = Matrix([[3, -2,? 4, -2], [5,? 3, -3, -2], [5, -2,? 2, -2], [5, -2, -3,? 3]])和M.eigenvals()得到{3: 1, -2: 1, 5: 2},,This means thatMhas eigenvalues -2, 3, and 5, and that the eigenvalues -2 and 3 have algebraic multiplicity 1 and that the eigenvalue 5 has algebraic multiplicity 2.

P, D = M.diagonalize(),P得Matrix([

[0, 1, 1,? 0],

[1, 1, 1, -1],

[1, 1, 1,? 0],

[1, 1, 0,? 1]]),,D為Matrix([

[-2, 0, 0, 0],

[ 0, 3, 0, 0],

[ 0, 0, 5, 0],

[ 0, 0, 0, 5]])

P*D*P**-1 == M返回為True。lamda = symbols('lamda')。

lamda = symbols('lamda')定義變量,p = M.charpoly(lamda)和factor(p)

expr = x**2 + x*y,srepr(expr)可以將表達(dá)式說明計算法則,"Add(Pow(Symbol('x'), Integer(2)), Mul(Symbol('x'), Symbol('y')))"。。

x = symbols('x')和x = Symbol('x')是一樣的。srepr(x**2)得到"Pow(Symbol('x'), Integer(2))"。Pow(x, 2)和Mul(x, y)得到x**2。x*y

type(2)得到class 'int',type(sympify(2))得到class 'sympy.core.numbers.Integer'..srepr(x*y)得到"Mul(Symbol('x'), Symbol('y'))"。。。

Add(Pow(x, 2), Mul(x, y))得到"Add(Mul(Integer(-1), Pow(Symbol('x'), Integer(2))), Mul(Rational(1, 2), sin(Mul(Symbol('x'), Symbol('y')))), Pow(Symbol('y'), Integer(-1)))"。。Pow函數(shù)為冪次。

expr = Add(x, x),expr.func。。Integer(2).func,class 'sympy.core.numbers.Integer',,Integer(0).func和Integer(-1).func,,,expr = 3*y**2*x和expr.func得到class 'sympy.core.mul.Mul',,expr.args將表達(dá)式分解為得到(3, x, y**2),,expr.func(*expr.args)合并。expr == expr.func(*expr.args)返回True。expr.args[2]得到y(tǒng)**2,expr.args[1]得到x,expr.args[0]得到3.。

expr.args[2].args得到(y, 2)。。y.args得到空括號。Integer(2).args得到空括號。

from sympy import *

E**(I*pi)+1,可以看出,I和E,pi已將在sympy內(nèi)已定義。

x=Symbol('x'),,expand( E**(I*x) )不能展開,expand(exp(I*x),complex=True)可以展開,得到I*exp(-im(x))*sin(re(x)) + exp(-im(x))*cos(re(x)),,x=Symbol("x",real=True)將x定義為實(shí)數(shù)。再展開expand(exp(I*x),complex=True)得到。I*sin(x) + cos(x)。。

tmp = series(exp(I*x), x, 0, 10)和pprint(tmp)打印出來可讀性好,print(tmp)可讀性不好。。pprint將公式用更好看的格式打印出來,,pprint( series( cos(x), x, 0, 10) )

integrate(x*sin(x), x),,定積分integrate(x*sin(x), (x, 0, 2*pi))。。

用雙重積分求解球的體積。

x, y, r = symbols('x,y,r')和2 * integrate(sqrt(r*r-x**2), (x, -r, r))計算球的體積。計算不來,是因?yàn)閟ympy不知道r是大于0的。r = symbols('r', positive=True)這樣定義r即可。circle_area=2*integrate(sqrt(r**2-x**2),(x,-r,r))得到。circle_area=circle_area.subs(r,sqrt(r**2-x**2))將r替換。

integrate(circle_area,(x,-r,r))再積分即可。

expression.sub([(x,y),(y,x)])又換到原來的狀況了。

expression.subs(x, y),,將算式中的x替換成y。。

expression.subs({x:y,u:v}) : 使用字典進(jìn)行多次替換。。

expression.subs([(x,y),(u,v)]) : 使用列表進(jìn)行多次替換。。

如何使用python做統(tǒng)計分析

Shape Parameters

形態(tài)參數(shù)

While a general continuous random variable can be shifted and scaled

with the loc and scale parameters, some distributions require additional

shape parameters. For instance, the gamma distribution, with density

γ(x,a)=λ(λx)a?1Γ(a)e?λx,

requires the shape parameter a. Observe that setting λ can be obtained by setting the scale keyword to 1/λ.

雖然一個一般的連續(xù)隨機(jī)變量可以被位移和伸縮通過loc和scale參數(shù),但一些分布還需要額外的形態(tài)參數(shù)。作為例子,看到這個伽馬分布,這是它的密度函數(shù)

γ(x,a)=λ(λx)a?1Γ(a)e?λx,

要求一個形態(tài)參數(shù)a。注意到λ的設(shè)置可以通過設(shè)置scale關(guān)鍵字為1/λ進(jìn)行。

Let’s check the number and name of the shape parameters of the gamma

distribution. (We know from the above that this should be 1.)

讓我們檢查伽馬分布的形態(tài)參數(shù)的名字的數(shù)量。(我們知道從上面知道其應(yīng)該為1)

from scipy.stats import gamma

gamma.numargs

1

gamma.shapes

'a'

Now we set the value of the shape variable to 1 to obtain the

exponential distribution, so that we compare easily whether we get the

results we expect.

現(xiàn)在我們設(shè)置形態(tài)變量的值為1以變成指數(shù)分布。所以我們可以容易的比較是否得到了我們所期望的結(jié)果。

gamma(1, scale=2.).stats(moments="mv")

(array(2.0), array(4.0))

Notice that we can also specify shape parameters as keywords:

注意我們也可以以關(guān)鍵字的方式指定形態(tài)參數(shù):

gamma(a=1, scale=2.).stats(moments="mv")

(array(2.0), array(4.0))

Freezing a Distribution

凍結(jié)分布

Passing the loc and scale keywords time and again can become quite

bothersome. The concept of freezing a RV is used to solve such problems.

不斷地傳遞loc與scale關(guān)鍵字最終會讓人厭煩。而凍結(jié)RV的概念被用來解決這個問題。

rv = gamma(1, scale=2.)

By using rv we no longer have to include the scale or the shape

parameters anymore. Thus, distributions can be used in one of two ways,

either by passing all distribution parameters to each method call (such

as we did earlier) or by freezing the parameters for the instance of the

distribution. Let us check this:

通過使用rv我們不用再更多的包含scale與形態(tài)參數(shù)在任何情況下。顯然,分布可以被多種方式使用,我們可以通過傳遞所有分布參數(shù)給對方法的每次調(diào)用(像我們之前做的那樣)或者可以對一個分布對象凍結(jié)參數(shù)。讓我們看看是怎么回事:

rv.mean(), rv.std()

(2.0, 2.0)

This is indeed what we should get.

這正是我們應(yīng)該得到的。

Broadcasting

廣播

The basic methods pdf and so on satisfy the usual numpy broadcasting

rules. For example, we can calculate the critical values for the upper

tail of the t distribution for different probabilites and degrees of

freedom.

像pdf這樣的簡單方法滿足numpy的廣播規(guī)則。作為例子,我們可以計算t分布的右尾分布的臨界值對于不同的概率值以及自由度。

stats.t.isf([0.1, 0.05, 0.01], [[10], [11]])

array([[ 1.37218364, 1.81246112, 2.76376946],

[ 1.36343032, 1.79588482, 2.71807918]])

Here, the first row are the critical values for 10 degrees of freedom

and the second row for 11 degrees of freedom (d.o.f.). Thus, the

broadcasting rules give the same result of calling isf twice:

這里,第一行是以10自由度的臨界值,而第二行是以11為自由度的臨界值。所以,廣播規(guī)則與下面調(diào)用了兩次isf產(chǎn)生的結(jié)果相同。

stats.t.isf([0.1, 0.05, 0.01], 10)

array([ 1.37218364, 1.81246112, 2.76376946])

stats.t.isf([0.1, 0.05, 0.01], 11)

array([ 1.36343032, 1.79588482, 2.71807918])

If the array with probabilities, i.e, [0.1, 0.05, 0.01] and the array of

degrees of freedom i.e., [10, 11, 12], have the same array shape, then

element wise matching is used. As an example, we can obtain the 10% tail

for 10 d.o.f., the 5% tail for 11 d.o.f. and the 1% tail for 12 d.o.f.

by calling

但是如果概率數(shù)組,如[0.1,0.05,0.01]與自由度數(shù)組,如[10,11,12]具有相同的數(shù)組形態(tài),則元素對應(yīng)捕捉被作用,我們可以分別得到10%,5%,1%尾的臨界值對于10,11,12的自由度。

stats.t.isf([0.1, 0.05, 0.01], [10, 11, 12])

array([ 1.37218364, 1.79588482, 2.68099799])

Specific Points for Discrete Distributions

離散分布的特殊之處

Discrete distribution have mostly the same basic methods as the

continuous distributions. However pdf is replaced the probability mass

function pmf, no estimation methods, such as fit, are available, and

scale is not a valid keyword parameter. The location parameter, keyword

loc can still be used to shift the distribution.

離散分布的簡單方法大多數(shù)與連續(xù)分布很類似。當(dāng)然像pdf被更換為密度函數(shù)pmf,沒有估計方法,像fit是可用的。而scale不是一個合法的關(guān)鍵字參數(shù)。Location參數(shù),關(guān)鍵字loc則仍然可以使用用于位移。

The computation of the cdf requires some extra attention. In the case of

continuous distribution the cumulative distribution function is in most

standard cases strictly monotonic increasing in the bounds (a,b) and

has therefore a unique inverse. The cdf of a discrete distribution,

however, is a step function, hence the inverse cdf, i.e., the percent

point function, requires a different definition:

ppf(q) = min{x : cdf(x) = q, x integer}

Cdf的計算要求一些額外的關(guān)注。在連續(xù)分布的情況下,累積分布函數(shù)在大多數(shù)標(biāo)準(zhǔn)情況下是嚴(yán)格遞增的,所以有唯一的逆。而cdf在離散分布,無論如何,是階躍函數(shù),所以cdf的逆,分位點(diǎn)函數(shù),要求一個不同的定義:

ppf(q) = min{x : cdf(x) = q, x integer}

For further info, see the docs here.

為了更多信息可以看這里。

We can look at the hypergeometric distribution as an example

from scipy.stats import hypergeom

[M, n, N] = [20, 7, 12]

我們可以看這個超幾何分布的例子

from scipy.stats import hypergeom

[M, n, N] = [20, 7, 12]

If we use the cdf at some integer points and then evaluate the ppf at

those cdf values, we get the initial integers back, for example

如果我們使用在一些整數(shù)點(diǎn)使用cdf,它們的cdf值再作用ppf會回到開始的值。

x = np.arange(4)*2

x

array([0, 2, 4, 6])

prb = hypergeom.cdf(x, M, n, N)

prb

array([ 0.0001031991744066, 0.0521155830753351, 0.6083591331269301,

0.9897832817337386])

hypergeom.ppf(prb, M, n, N)

array([ 0., 2., 4., 6.])

If we use values that are not at the kinks of the cdf step function, we get the next higher integer back:

如果我們使用的值不是cdf的函數(shù)值,則我們得到一個更高的值。

hypergeom.ppf(prb + 1e-8, M, n, N)

array([ 1., 3., 5., 7.])

hypergeom.ppf(prb - 1e-8, M, n, N)

array([ 0., 2., 4., 6.])

excel gammainv函數(shù)對應(yīng)python函數(shù)?

1.GAMMA.INV函數(shù)的功能 計算伽瑪累積分布函數(shù)的反函數(shù)值。

2.GAMMA.INV函數(shù)的語法結(jié)構(gòu) GAMMA.INV(probability,...

3.GAMMA.INV函數(shù)的使用方法 以如下表格為例,演示該函數(shù)的使用方法;

4.第一步,在輸出結(jié)果的單元格,輸入函數(shù)公式,即 =GAMMA.INV;

5.第二步,設(shè)定參數(shù)Probability;

分享名稱:python調(diào)用伽馬函數(shù) 函數(shù)的調(diào)用Python
本文URL:http://muchs.cn/article30/hgigso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、服務(wù)器托管網(wǎng)站排名、網(wǎng)站設(shè)計、網(wǎng)頁設(shè)計公司、商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管