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


Python math.fact函数代码示例

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


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

示例1: __ecMatch__

 def __ecMatch__(self, seq, ref):
     if len(ref)==0: # shitty lines
         return -100,0
         
     oneago = None
     thisrow = range(1, len(ref) + 1) + [0]
     for x in xrange(len(seq)):
         twoago, oneago, thisrow = oneago, thisrow, [0] * len(ref) + [x + 1]
         for y in xrange(len(ref)):
             delcost = oneago[y] + 1
             addcost = thisrow[y - 1] + 1
             subcost = oneago[y - 1] + (seq[x] != ref[y])
             thisrow[y] = min(delcost, addcost, subcost)
     # return thisrow[len(ref) - 1],len(ref)
     thisrow.pop() # eliminate last element
     n = thisrow.index(min(thisrow))+1
     #n = len(thisrow)-thisrow[-1::-1].index(min(thisrow)) 
     d = thisrow[n-1]
     # print seq
     # print ref
     # print thisrow
     # print d,n
     d = min(d,n)
     #n=max(d,len(seq))
     #print d,n
     err_lsc = d*log(self.err_p) + (n-d)*log(1.0-self.err_p) + log(fact(n))-(log(fact(d))+log(fact(n-d)))
     return err_lsc,n
开发者ID:jesus-g-rubio,项目名称:syntax-ITP,代码行数:27,代码来源:hISLES-PD-limEffort.py

示例2: problem_53

def problem_53():
    from math import factorial as fact
    c=0
    for n in range(1,101):
        for r in range(1,n):
            if fact(n)/(fact(r)*fact(n-r))>1000000:c+=1
    return c
开发者ID:toddsifleet,项目名称:project_euler,代码行数:7,代码来源:Euler.py

示例3: GetChanceOfDominantTraits

def GetChanceOfDominantTraits(organisms):
	totalOutcomes = 4.0 * fact(len(organisms)) / (2*fact(len(organisms)-2)) 
	totalDominantOutcomes = 0.0
	for i in range(0, len(organisms)-1):
		for j in range(i+1, len(organisms)):
			totalDominantOutcomes += CountDominantAleleCombos(organisms[i], organisms[j])
	return totalDominantOutcomes / totalOutcomes
开发者ID:kharland,项目名称:Rosalind-Solutions,代码行数:7,代码来源:IPRB.py

示例4: main

def main():
    from sys import stdin,stdout
    from math import factorial as fact
    from collections import Counter
    k = int(stdin.readline().strip())
    s = stdin.readline().strip()
    c = Counter(s)
    stdout.write(str(fact(k)/fact(len(filter(lambda x: x>1,c.values())))))
开发者ID:Hygens,项目名称:hackerearth_hackerrank_solutions,代码行数:8,代码来源:LittleShinoandCoins_2.py

示例5: findFactorialSum

def findFactorialSum():
    factorials = [fact(x) for x in range(0, 10)] # pre-calculate products
    total_sum = 0
    for k in range(10, fact(9) * 7): # 9999999 is way more than its fact-sum
        if sum([factorials[int(x)] for x in str(k)]) == k:
            total_sum += k

    return total_sum
开发者ID:paulmcquad,项目名称:projecteuler,代码行数:8,代码来源:problem34.py

示例6: Enum

def Enum(x):
    
    res = 1
    
    for i in xrange(1,x+1):
        res += fact(x)/(fact(x-i)*fact(i))
    
    
    return res % 1000000
开发者ID:87875172,项目名称:rosalind,代码行数:9,代码来源:Counting+Subsets.py

示例7: run

def run():
    count = 0
    for n in xrange(23, 101):
        r = 1
        fn = fact(n)
        while fn / fact(r) / fact(n - r) < 10**6:
            r += 1
        o = 2 * (int(n / 2) + 1 - r) - (1 if n % 2 == 0 else 0)
        count += o
    return count
开发者ID:bozakp,项目名称:project-euler,代码行数:10,代码来源:p053.py

示例8: comb

def comb(n, k):
    if (k > n):
        return 0
    else:
        if (k == n):
            return 1
        else:
            #print(n)
            #print(k)
            return ((fact(n))/((fact(k))*(fact(n-k))))
开发者ID:bcoburn3,项目名称:findingdredge,代码行数:10,代码来源:nialo.py

示例9: sph_harm_large

def sph_harm_large(m, n, az, el):
    """Compute spherical harmonics for large orders > 84

    Parameters
    ----------
    m : (int)
        Order of the spherical harmonic. abs(m) <= n

    n : (int)
        Degree of the harmonic, sometimes called l. n >= 0

    az: (float)
        Azimuthal (longitudinal) coordinate [0, 2pi], also called Theta.

    el : (float)
        Elevation (colatitudinal) coordinate [0, pi], also called Phi.

    Returns
    -------
    y_mn : (complex float)
        Complex spherical harmonic of order m and degree n,
        sampled at theta = az, phi = el

    Y_n,m (theta, phi) = ((n - m)! * (2l + 1)) / (4pi * (l + m))^0.5 * exp(i m phi) * P_n^m(cos(theta))
    as per http://dlmf.nist.gov/14.30
    Pmn(z) is the associated Legendre function of the first kind, like scipy.special.lpmv
    scipy.special.lpmn calculates P(0...m 0...n) and its derivative but won't return +inf at high orders
    """
    if _np.all(_np.abs(m) < 84):
        return scy.sph_harm(m, n, az, el)
    else:

        # TODO: confirm that this uses the correct SH definition

        mAbs = _np.abs(m)
        if isinstance(el, _np.ndarray):
            P = _np.empty(el.size)
            for k in range(0, el.size):
                P[k] = scy.lpmn(mAbs, n, _np.cos(el[k]))[0][-1][-1]
        else:
            P = scy.lpmn(mAbs, n, _np.cos(el))[0][-1][-1]
        preFactor1 = _np.sqrt((2 * n + 1) / (4 * _np.pi))
        try:
            preFactor2 = _np.sqrt(fact(n - mAbs) / fact(n + mAbs))
        except OverflowError:  # integer division for very large orders
            preFactor2 = _np.sqrt(fact(n - mAbs) // fact(n + mAbs))

        Y = preFactor1 * preFactor2 * _np.exp(1j * m * az) * P
        if m < 0:
            return _np.conj(Y)
        else:
            return Y
开发者ID:QULab,项目名称:sound_field_analysis-py,代码行数:52,代码来源:sph.py

示例10: count_pairs

def count_pairs(a):
    a.sort()
    cnt = 0
    repeat = 1
    for i in range(1, len(a)):
        if a[i-1] == a[i]:
            repeat += 1
        else:
            if repeat > 1:
                cnt += fact(repeat) / fact(repeat-2) # permutation (n 2)
            repeat = 1
    if repeat > 1:
        cnt += fact(repeat) / fact(repeat-2)
    return int(cnt)
开发者ID:bmpasini,项目名称:coding-challenges,代码行数:14,代码来源:sherlock-and-pairs.py

示例11: S

def S(n):
  N = n+1
  numbers = [ i for i in range(N) ]
  r = ''
  p = 1000000-1
  for i in range(1, N):
    j = p // fact(N-i)
    p %= fact(N-i)
    r += str(numbers.pop(j))
    if p == 0:
      break
  for n in numbers:
    r += str(n)
  return r
开发者ID:bmpasini,项目名称:project-euler,代码行数:14,代码来源:24.py

示例12: problem_74

def problem_74():
    from math import factorial as fact
    cnt = 0
    c=0
    for i in xrange(1000000):
        c+= 1
        if not c%10000: print c,cnt
        l = []
        while i not in l:
            l.append(i)
            reduce(lambda a,b: a + fact(int(n)),string(i))
            i = sum([fact(int(n)) for n in str(i)])
        if len(l)==60:cnt+=1

    return cnt
开发者ID:toddsifleet,项目名称:project_euler,代码行数:15,代码来源:Euler.py

示例13: S5

 def S5(self, Pb, Pj):
     t1 = (
         (self.c ** self.c / fact(self.c))
         * (self.xi(Pb) ** self.ns)
         * sum([self.eta(Pj) ** (k - self.ns) for k in range(self.ns, self.n)])
     )
     return float(t1)
开发者ID:cpatdowling,项目名称:net-queue,代码行数:7,代码来源:qgfig1.py

示例14: p0

 def p0(self,Pb,Pj):
     xi_  = self.xi(Pb)
     eta_ = self.eta(Pj)
     t1   = self.S1(Pb)+self.S2(Pb)
     t2   = ((self.c**self.c/fact(self.c))*xi_**(self.ns)
                 *(1-eta_**(self.n-1-self.ns))/(1-eta_))
     return float(((t1+t2)**(-1)))
开发者ID:cpatdowling,项目名称:net-queue,代码行数:7,代码来源:qgfig4.py

示例15: __searchBestNodeMatch__

 def __searchBestNodeMatch__(self, pref_s):
     if len(pref_s)==0:
         node=self.__nodes__[self.__init_node__]
         ec_lsc = node.getInsideLogScore()+node.getOutsideLogScore()
         return self.__init_node__,ec_lsc,ec_lsc
     
     pref = " ".join(pref_s).strip()
     n = len(pref)
     max_lsc = float("-inf")
     max_node = None
     ordered_keys = sorted(self.__nodes__)
     #inside x outside x err
     for n_idx in ordered_keys:
         covered_sent = self.__nodes__[n_idx].getCoveredString().strip()
         if covered_sent[0:3] == "<s>": #consider only nodes covering a prefix
             covered_sent = covered_sent.replace("|UNK|UNK|UNK","").replace("<s>","").replace("</s>","").strip()
             d = Levenshtein.distance(pref,covered_sent)
             d = min(d,n)
             err_lsc = d*log(self.err_p) + (n-d)*log(1.0-self.err_p) + log(fact(n))-(log(fact(d))+log(fact(n-d)))
             itp_lsc = self.__nodes__[n_idx].getInsideLogScore()+self.__nodes__[n_idx].getOutsideLogScore()
             cur_lsc = itp_lsc+self.err_w*err_lsc
             if cur_lsc > max_lsc:
                 max_lsc = cur_lsc
                 max_itp_lsc = itp_lsc
                 max_node = n_idx
                 # print "\n-----------------------"
             #     print pref,"#",covered_sent,"#",n,"->",d
             #     print max_lsc, max_itp_lsc, err_lsc
             #     print self.__nodes__[max_node]
             #     print "-----------------------\n"
             # else:
             #     print " -->","#"+covered_sent+"#",d,cur_lsc,itp_lsc,err_lsc
     return max_node,max_lsc,max_itp_lsc
开发者ID:jesus-g-rubio,项目名称:syntax-ITP,代码行数:33,代码来源:hIMT.py


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