当前位置: 首页>>代码示例>>Python>>正文


Python scipy.factorial函数代码示例

本文整理汇总了Python中scipy.factorial函数的典型用法代码示例。如果您正苦于以下问题:Python factorial函数的具体用法?Python factorial怎么用?Python factorial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了factorial函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: alpha

 def alpha(k,m,n):
     tau = t_intervals[n-1]
     i = np.arange(m+1)[:,np.newaxis]
     the_sum = np.sum((1j*k*omega)**(-m+i-1) * \
                          tau[:,np.newaxis]**i / factorial(i), axis=-2)
     integral = -factorial(m) * np.exp(-1j * k * omega * tau) * the_sum
     return integral[:,1] - integral[:,0]
开发者ID:dreyfert,项目名称:pycircuit,代码行数:7,代码来源:fourier.py

示例2: Combinations

def Combinations(values, k):
    """This function outputs all possible combinations of k elements from the column vector values"""
    n = len(values)
    try:
        values = sp.row_stack(values)
    except:
        raise ValueError, "I need a 2d column array"

    if k > n:
        raise ValueError, "k must be <= %d" % n
    elif k<=0 or k%1 != 0:
        raise ValueError, "k must be > 0"

    #out = sp.array([],ndmin=2)
    if k == 1:
        return values
    else:
        #This loop iterates through all the elements of the values that have at least
        #k elements.  For each element it then calls Combinations(values[i+1:], k-1) which
        #returns combinations of size k-1 for the elements succeeding the current element
        #We do not want to get repeats of combinations
        #print "for i in range(%d)" % (n-(k-1))
        for i in range(n-(k-1)):
            #Calculate the number of possible combinations (to allow proper concatenation
            #in the recursive call
            numCombs = sp.factorial(n-i)/(sp.factorial(k-1)*sp.factorial(n-i-(k-1)))
            combs = Combinations(values[i:], k-1)
            ones = values[i]*sp.ones((numCombs,1))
            #print "ones: %s \t\t combs: %s" % (str(ones.shape), str(combs.shape))
            print combs
开发者ID:KathleenF,项目名称:numerical_computing,代码行数:30,代码来源:combinatorics.py

示例3: prehamiltonian

def prehamiltonian( genlags, EC, EJ, EL ):
    ### NB: omits a factor of EJ (on top of the flux dependency and the 
    ### diagonal terms) for use as a derivative later
    size = len(genlags)
    hbar_w0 = sqrt( 8. * EL * EC )
    phi0 = ( 8. * EC / EL ) ** .25 
    arg = phi0**2/2
    
    genlags = [[ f(arg) for f in row ] for row in genlags]
    ret = [ range(size) for i in range(size) ] #values set below

    for row in range(size):
        for col in range(size):
            #the nonzero cosine elements
            if (col-row)%2==0:
                n = min(row,col)
                m = abs(col-row)/2 # because of Hermitianness
                ret[row][col] = -(-2)**-m \
                    * sqrt(factorial(n)/factorial(n+2*m)) \
                    * phi0**(2*m) * exp(phi0**2/-4) \
                    * genlags[n][2*m]
            #the nonzero sine elements
            else:
                ### IS THIS PART RIGHT?
                n = min(row,col)
                m = (abs(col-row)-1)/2
                ret[row][col] = -(-2)**(-m) * 2**-.5 \
                    * sqrt(factorial(n)/factorial(n+2*m+1)) \
                    * phi0**(2*m+1) * exp(phi0**2/-4) \
                    * genlags[n][2*m+1] ## Check overall signs
    return array(ret)
开发者ID:oconnor663,项目名称:cooper_pair_box,代码行数:31,代码来源:CPBL.py

示例4: Combinations

def Combinations(values, k):
    """This function outputs all the possible combinations of k elements from the vector values"""
    
    if int(k) < 0:
        raise ValueError("k must a positive integer")
    
    #Make input vectors column vectors
    if values.shape == (1,values.size):
        values = sp.atleast2d(values).T.copy()
    
    out = sp.array([]).reshape(0,1)
    n = max(values.shape)
    if k == 1:
        out = values
    else:
        #the following loop interates through all the elements of the vector values that have at least k elements after them.  For each element it then calls Combinations(values[i+1:], k-1) which returns combinations of size k-1 for the elements succeeding the current element.  This is so that we do not get repeats of combinations
        #nck = sp.misc.comb(n,k, exact=True)
        #out = sp.zeros((nck, k))
        for i in range(n-(k-1)):
            #Calculate the number of possible combinations (to allow proper concatenation in the recursive call
            nCombs = int(sp.factorial(n-i)/(sp.factorial(k-1)*sp.factorial(n-i-(k-1))))
            #This is the recursive call
            
            print Combinations(values[i+1:], k-1).reshape((-1,1))
            out = sp.r_[out, sp.c_[values[i]*sp.ones((nCombs,1)), Combinations(values[i+1:], k-1).reshape(-1,1)]]
            
    return out
开发者ID:shorst22,项目名称:numerical_computing,代码行数:27,代码来源:combinations.py

示例5: _sch_lpmv

def _sch_lpmv(n,x):
	'''
	Outputs array of Schmidt Seminormalized Associated Legendre Functions S_{n}^{m} for m<=n.
	
	Parameters
	----------
	n : int 
	    Degree of polynomial.
	
	x : float 
	    Point at which to evaluate
	
	Returns
	-------
	array of values for Legendre functions. 
	
	'''
	from scipy.special import lpmv
	sch=array([1.0])
	sch2=array([(-1.0)**m*sqrt((2.0*factorial(n-m))/factorial(n+m)) for m in range(1,n+1)])
	sch=append(sch,sch2)
	if isinstance(x,float) or len(x)==1:
		leg=lpmv(arange(0,n+1),n,x)
		return array([sch*leg]).T
	else:
		for j in range(0,len(x)):
			leg=lpmv(range(0,n+1),n,x[j])
			if j==0:
				out=array([sch*leg]).T
			else:
				out=append(out,array([sch*leg]).T,axis=1)
	return out
开发者ID:niazalikhan87,项目名称:qutip,代码行数:32,代码来源:orbital.py

示例6: delta

 def delta(a,b,c):
     """ Calculate delta """
     fac = zeros(4,long)
     fac[0] = factorial(a+b-c)
     fac[1] = factorial(a-b+c)
     fac[2] = factorial(-a+b+c)
     fac[3] = factorial(a+b+c+1)
     return sqrt(prod(fac[0:3])/fac[3]);
开发者ID:imrehg,项目名称:physicspy,代码行数:8,代码来源:atomic.py

示例7: basis2d

def basis2d(n0,n1,beta=[1.,1.]):
    """2d dimensionless Cartesian basis function"""
    b=hermite2d(n0,n1)
    b[0]*=((2**n0)*(n.pi**(.5))*scipy.factorial(n0))**(-.5)
    exp0=lambda x: beta[0] * b[0](x) * n.exp(-.5*(x**2))
    b[1]*=((2**n1)*(n.pi**(.5))*scipy.factorial(n1))**(-.5)
    exp1=lambda x: beta[1] * b[1](x) * n.exp(-.5*(x**2))
    return [exp0,exp1]
开发者ID:cdeil,项目名称:shapelets,代码行数:8,代码来源:shapelet.py

示例8: bernstein

def bernstein(n):
    """ Bernstein-Polynome (n!/(i!(n-i)!)* t^i (1-t)^(n-i)"""
    t = linspace(0,1,20)

    bmat = zeros((20,n+1))
    for i in range(0,n+1):
        bmat[:,i] = sp.factorial(n)/(sp.factorial(i)*sp.factorial(n-i))*t**i*(1-t)**(n-i)
    return bmat
开发者ID:laevar,项目名称:mapy,代码行数:8,代码来源:e4a8.py

示例9: plot_messung

def plot_messung(n, t, b_len, y_lim, lens, rate):
    mu, sigma = np.mean(n), np.std(n)
    print "Mittelwert: %.3f" % mu
    print "Varianz: %.3f Poisson: %.3f" % (sigma ** 2, mu)
    print "Standardabweichung: %.3f Poisson: %.3f" % (sigma, np.sqrt(mu))
    print "Standardabweichung des Mittelwerts: %.3f Poisson: %.3f" % (
        sigma / np.sqrt(len(n)),
        np.sqrt(mu) / np.sqrt(len(n)),
    )
    print "Gesamtanzahl der Ereignisse:", np.sum(n)
    print "mittlere Zaehlrate: %.3f 1/s" % (np.mean(n) / (rate))
    print "Standardabweichung der Zaehlrate: %.3f 1/s" % (np.std(n) / rate)
    print "Standardabweichung der mittleren Zaehlrate: %.3f 1/s" % (np.std(n) / rate / np.sqrt(len(n)))
    print "Schiefe: %.3f Poisson: %.3f" % (np.mean((n - n.mean()) ** 3) / sigma ** 3, 1 / np.sqrt(mu))
    print "Kurtosis: %.3f Poisson: %.3f" % (np.mean((n - n.mean()) ** 4) / sigma ** 4 - 3, 1 / (mu))
    print ""
    fig = plt.figure(figsize=(16, 12))
    ax = fig.add_subplot(111)

    # the histogram of the data
    n, bins, patches = ax.hist(n, lens, normed=1, facecolor="yellow", alpha=0.75)

    bincenters = 0.5 * (bins[1:] + bins[:-1])
    b = np.linspace(0, b_len, 1000)
    b2 = np.arange(0, b_len, 1) + 0.5

    # add a 'best fit' line for the normal PDF
    # y = mlab.normpdf( b, mu, sigma)
    # y2 =mlab.normpdf( b2, mu, sigma)
    # l = ax.plot(b, y, 'b--', linewidth=1)
    poisson = lambda k: 1.0 / (sc.factorial(k) * np.exp(mu)) * mu ** k
    poisson2 = lambda k: 1.0 / (sc.factorial(k) * np.exp(mu + sigma)) * (mu + sigma) ** k
    poisson3 = lambda k: 1.0 / (sc.factorial(k) * np.exp(mu - sigma)) * (mu - sigma) ** k
    normal_k = lambda k: 1.0 / np.sqrt(2 * np.pi * mu) * np.exp(-(k - mu) ** 2 / (2 * mu))
    normal_k2 = (
        lambda k: 1.0 / np.sqrt(2 * np.pi * (mu + sigma)) * np.exp(-(k - (mu + sigma)) ** 2 / (2 * (mu + sigma)))
    )
    normal_k3 = (
        lambda k: 1.0 / np.sqrt(2 * np.pi * (mu - sigma)) * np.exp(-(k - (mu - sigma)) ** 2 / (2 * (mu - sigma)))
    )

    nk = ax.plot(b, normal_k(b), "g--", linewidth=1)
    nk = ax.plot(b, normal_k2(b), "g--", linewidth=1)
    nk = ax.plot(b, normal_k3(b), "g--", linewidth=1)
    p = ax.plot(b, poisson(b), "r--", linewidth=1)
    p = ax.plot(b, poisson2(b), "r--", linewidth=1)
    p = ax.plot(b, poisson3(b), "r--", linewidth=1)
    l = ax.scatter(b2, normal_k(b2), marker="x", c="b")
    p = ax.scatter(b2, poisson(b2), marker="x", c="b")

    ax.set_xlabel("Anzahl der Impulse")
    ax.set_ylabel("Wahrscheinlichkeit")
    plt.xlim(0, b_len)
    plt.ylim(0, y_lim)
    ax.grid(True)

    plt.show()
开发者ID:vsilv,项目名称:studyrepo,代码行数:57,代码来源:versuch24.py

示例10: dimBasis2d

def dimBasis2d(n0,n1,beta=[1.,1.],phs=[1.,1.]):
    """2d dimensional Cartesian basis function of characteristic size beta
    phs: additional phase factor, used in the Fourier Transform"""
    b=hermite2d(n0,n1)
    b[0]*=(beta[0]**(-.5))*(((2**n0)*(n.pi**(.5))*scipy.factorial(n0))**(-.5))
    exp0=lambda x: b[0](x/beta[0]) * n.exp(-.5*((x/beta[0])**2)) * phs[0]
    b[1]*=(beta[1]**(-.5))*(((2**n1)*(n.pi**(.5))*scipy.factorial(n1))**(-.5))
    exp1=lambda x: b[1](x/beta[1]) * n.exp(-.5*((x/beta[1])**2)) * phs[1]
    return [exp0,exp1]
开发者ID:cdeil,项目名称:shapelets,代码行数:9,代码来源:shapelet.py

示例11: C

def C(n, r):
    if n - r > r:
        num = np.prod(np.arange(n - r + 1, n+1))
        den = factorial(r)
        return num / den
    else:
        num = np.prod(np.arange(r + 1, n+1))
        den = factorial(n - r)
        return num / den
开发者ID:MathYourLife,项目名称:Project-Euler,代码行数:9,代码来源:Statistics.py

示例12: plot_pdf

def plot_pdf(order, N, iterations):
	order_stats = []
	for it in range(iterations):
		numbers = [np.random.uniform(0,1) for i in range(N)]
		numbers.sort()
		order_stats.append(numbers[order-1])
	plt.figure()
	n, bins, patches = plt.hist(order_stats, iterations/20, normed=1, facecolor='green')
	y = lambda x: int(sp.factorial(N))/(int(sp.factorial(N-order))*int(sp.factorial(order-1))) * x**(order-1) * (1-x)**(N-order)
	plt.plot(bins, y(bins), 'r--', linewidth=3)
开发者ID:kubkon,项目名称:Phd-python,代码行数:10,代码来源:uniform_order_statistics.py

示例13: factorialQuotient

def factorialQuotient(numerator, denominator):
    """
    result=numerator!/(denominator!)
    """
    diff = numerator - denominator
    if diff > 0:
        result = factorial(diff)
    else:
        result = 1.0 / factorial(-diff)
    return result
开发者ID:kte608,项目名称:MagnetoShim,代码行数:10,代码来源:SH_Definitions.py

示例14: Wigner6j

def Wigner6j(j1,j2,j3,J1,J2,J3):
#======================================================================
# Calculating the Wigner6j-Symbols using the Racah-Formula                
# Author: Ulrich Krohn                                            
# Date: 13th November 2009
#                                                                         
# Based upon Wigner3j.m from David Terr, Raytheon                         
# Reference: http://mathworld.wolfram.com/Wigner6j-Symbol.html            
#
# Usage: 
# from wigner import Wigner6j
# WignerReturn = Wigner6j(j1,j2,j3,J1,J2,J3)
#
#  / j1 j2 j3 \
# <            >  
#  \ J1 J2 J3 /
#
#======================================================================

    # Check that the js and Js are only integer or half integer
    if ( ( 2*j1 != round(2*j1) ) | ( 2*j2 != round(2*j2) ) | ( 2*j2 != round(2*j2) ) | ( 2*J1 != round(2*J1) ) | ( 2*J2 != round(2*J2) ) | ( 2*J3 != round(2*J3) ) ):
        print 'All arguments must be integers or half-integers.'
        return -1
    
# Check if the 4 triads ( (j1 j2 j3), (j1 J2 J3), (J1 j2 J3), (J1 J2 j3) ) satisfy the triangular inequalities
    if ( ( abs(j1-j2) > j3 ) | ( j1+j2 < j3 ) | ( abs(j1-J2) > J3 ) | ( j1+J2 < J3 ) | ( abs(J1-j2) > J3 ) | ( J1+j2 < J3 ) | ( abs(J1-J2) > j3 ) | ( J1+J2 < j3 ) ):
        print '6j-Symbol is not triangular!'
        return 0
    
    # Check if the sum of the elements of each traid is an integer
    if ( ( 2*(j1+j2+j3) != round(2*(j1+j2+j3)) ) | ( 2*(j1+J2+J3) != round(2*(j1+J2+J3)) ) | ( 2*(J1+j2+J3) != round(2*(J1+j2+J3)) ) | ( 2*(J1+J2+j3) != round(2*(J1+J2+j3)) ) ):
        print '6j-Symbol is not triangular!'
        return 0
    
    # Arguments for the factorials
    t1 = j1+j2+j3
    t2 = j1+J2+J3
    t3 = J1+j2+J3
    t4 = J1+J2+j3
    t5 = j1+j2+J1+J2
    t6 = j2+j3+J2+J3
    t7 = j1+j3+J1+J3

    # Finding summation borders
    tmin = max(0, max(t1, max(t2, max(t3,t4))))
    tmax = min(t5, min(t6,t7))
    tvec = arange(tmin,tmax+1,1)
        
    # Calculation the sum part of the 6j-Symbol
    WignerReturn = 0
    for t in tvec:
        WignerReturn += (-1)**t*factorial(t+1)/( factorial(t-t1)*factorial(t-t2)*factorial(t-t3)*factorial(t-t4)*factorial(t5-t)*factorial(t6-t)*factorial(t7-t) )

    # Calculation of the 6j-Symbol
    return WignerReturn*sqrt( TriaCoeff(j1,j2,j3)*TriaCoeff(j1,J2,J3)*TriaCoeff(J1,j2,J3)*TriaCoeff(J1,J2,j3) )
开发者ID:astrofanlee,项目名称:project_TL,代码行数:55,代码来源:wigner.py

示例15: multivariate_polya_vectorized

def multivariate_polya_vectorized(x,alpha):
    """Multivariate Pólya PDF. Vectorized implementation.
    """
    x = np.atleast_1d(x)
    alpha = np.atleast_1d(alpha)
    assert(x.size==alpha.size)
    N = x.sum()
    A = alpha.sum()
    likelihood = factorial(N) / factorial(x).prod() * gamma(A) / gamma(N + A)
    likelihood *= (gamma(x + alpha) / gamma(alpha)).prod()
    return likelihood
开发者ID:dweissman,项目名称:inference_with_classifiers,代码行数:11,代码来源:multivariate_polya.py


注:本文中的scipy.factorial函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。