本文整理汇总了Python中math.fact函数的典型用法代码示例。如果您正苦于以下问题:Python fact函数的具体用法?Python fact怎么用?Python fact使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fact函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: __searchNbestNodeMatchRestricted__
def __searchNbestNodeMatchRestricted__(self, segm_s, segm_best, valid_nodes, is_prefix):
# TODO:
segm = " ".join(segm_s).strip()
n = len(segm)
# max_lsc = float("-inf")
# max_node = None
nbest_nodes = []
for n_idx in valid_nodes:
covered_sent = self.__nodes__[n_idx].getCoveredString().strip()
if not is_prefix or (is_prefix and covered_sent[0:3] == "<s>"):
covered_sent = covered_sent.replace("|UNK|UNK|UNK","").replace("<s>","").replace("</s>","").strip()
d = Levenshtein.distance(segm,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 #inside x outside x err**err_w
# if cur_lsc > max_lsc:
# max_lsc = cur_lsc
# max_itp_lsc = itp_lsc
# max_node = n_idx
if len(nbest_nodes)<=segm_best or cur_lsc>nbest_nodes[0][0]:
nbest_nodes.append((cur_lsc,itp_lsc,n_idx))
nbest_nodes = sorted(nbest_nodes)[-segm_best:]
#print nbest_nodes
#return max_lsc,max_itp_lsc,max_node
still_more_options = True
if len(nbest_nodes)<segm_best:
still_more_options = False
return nbest_nodes[0],still_more_options
开发者ID:jesus-g-rubio,项目名称:syntax-ITP,代码行数:30,代码来源:hISLES-limEffort.py
示例17: calc_loss_combinations
def calc_loss_combinations(n, prob_down):
total_loss = 0
prob_up = 1.0 - prob_down
total_probs = 0
for i in xrange(1, n+1):
combs = fact(n * 2) / (fact(n+i) * fact(n-i))
prob = prob_up ** (n+i) * prob_down ** (n-i)
single_loss = (i*2) * combs * (prob * 2)
total_loss += single_loss
print "combs: {}".format(combs)
if i > 0:
total_probs += (prob * 2 * combs)
else:
total_probs += (prob * combs)
return total_loss, total_probs
开发者ID:Akavall,项目名称:Profit-Calculation-and-Simulation,代码行数:16,代码来源:simulation_combs.py
示例18: get_random_ranks
def get_random_ranks(permsize, samplesize):
perms = fact(permsize)
ranks = set()
while len(ranks) < samplesize:
ranks |= set( randrange(perms)
for r in range(samplesize - len(ranks)) )
return ranks
开发者ID:Anatolt,项目名称:RosettaCodeData,代码行数:7,代码来源:permutations-rank-of-a-permutation-1.py
示例19: pieinsky
def pieinsky():
c1 = Decimal(4)
c2 = Decimal(1103)
c3 = Decimal(26390)
c4 = Decimal(396)
c5 = Decimal(9801)
# code formatted for readability (make it be one line)
root8 = Decimal('2.82842712474619009760337744841939615'
'7139343750753896146353359475981464956'
'9242140777007750686552831454700276')
i = Decimal(0)
thesum = Decimal(0)
while True:
term = (fact(c1*i)*(c2 + c3*i))/(pow(fact(i),4)*pow(c4,4*i))
thesum = thesum + term
yield 1/((root8/c5)*thesum)
i += 1
开发者ID:mklump,项目名称:codeguild_pythoncamp,代码行数:17,代码来源:ramanujan.py
示例20: __searchNbestNodeMatchRestricted__
def __searchNbestNodeMatchRestricted__(self, segm_s, segm_best, valid_nodes, first_isle):
segm = " ".join(segm_s).strip()
n = len(segm)
#print "SN:",segm_s, segm_best, len(valid_nodes), first_isle
nbest_nodes = []
for n_idx in valid_nodes:
covered_sent_s,inside_lsc = valid_nodes[n_idx]
#print n_idx,covered_sent_s,inside_lsc
# all nodes represent prefixes
# "|||" symbol represents previous matching
# search for node whith best EC score on the unmatched suffix
if first_isle:
covered_sent = " ".join(covered_sent_s).replace("|UNK|UNK|UNK","").replace("</s>","").strip()
d = Levenshtein.distance(segm,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 #inside x outside x err**err_w
if len(nbest_nodes)<=segm_best or cur_lsc>nbest_nodes[0][0]:
nbest_nodes.append((cur_lsc,itp_lsc,n_idx,segm_s))
nbest_nodes = sorted(nbest_nodes)[-segm_best:]
#print "P",covered_sent,d,err_lsc,itp_lsc,cur_lsc
#print "P",nbest_nodes
else:
max_suffix_size = len(covered_sent_s)-covered_sent_s.index("|||")
for suffix_size in range(1,max_suffix_size):
covered_sent = " ".join(covered_sent_s[-suffix_size:]).replace("|UNK|UNK|UNK","").replace("</s>","").strip()
d = Levenshtein.distance(segm,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 #inside x outside x err**err_w
if len(nbest_nodes)<=segm_best or cur_lsc>nbest_nodes[0][0]:
out_str = covered_sent_s[:-suffix_size]+tuple(segm_s)
nbest_nodes.append((cur_lsc,itp_lsc,n_idx,out_str))
nbest_nodes = sorted(nbest_nodes)[-segm_best:]
#print "I",covered_sent,d,err_lsc,itp_lsc,cur_lsc
#print "I", nbest_nodes
#print nbest_nodes
#return max_lsc,max_itp_lsc,max_node
#sys.exit()
still_more_options = True
if len(nbest_nodes)<segm_best:
still_more_options = False
return nbest_nodes[0],still_more_options
开发者ID:jesus-g-rubio,项目名称:syntax-ITP,代码行数:46,代码来源:wISLES-limEffort.py
注:本文中的math.fact函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论