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


Python pow函数代码示例

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


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

示例1: test_good_result

 def test_good_result(self):
   # Note: All of these cases use integers, and would fail if the float() casts
   #       were to be remvoed from get_safe_feedrate. Try it.
   cases = [
     [[1,  0, 0, 0, 0],    # Single axis: Move under the max feedrate
      [10, 0, 0, 0, 0],
      1, 1],
     [[11, 0, 0, 0, 0],    # Single axis: Move at the max feedrate
      [2,  0, 0, 0, 0],
      2, 2],
     [[-12,0, 0, 0, 0],    # Single axis: Move in negative direction at the max feedrate
      [1,  0 ,0, 0, 0],
      1, 1],
     [[13, 0, 0, 0, 0],    # Single axis: Move faster than the max feedrate
      [1,  0, 0, 0, 0],
      10, 1],
     [[1, -1, 1,-1, 1],    # Multi axis: Move in negative direction at the max feedrate
      [1,  1, 1, 1, 1],
      pow(5,.5), pow(5,.5)],
     [[1, -2, 3,-4, 5],    # Multi axis: Move faster than the max feedrate
      [1,  1, 1, 1, 1],
      10, pow(55,.5)/5],
   ]
   for case in cases:
     self.assertEquals(case[3], makerbot_driver.Gcode.get_safe_feedrate(case[0], case[1], case[2]))
开发者ID:ricberw,项目名称:s3g,代码行数:25,代码来源:pi_test_GcodeUtils.py

示例2: __setXYZData

 def __setXYZData(self, pixel, x, y):
     if(pixel[0] < 0.04045):
         r = pixel[0]/12.92
     else:
         r = pow((pixel[0] + 0.055)/1.055, 2.4)
     if(pixel[1] < 0.04045):
         g = pixel[1]/12.92
     else:
         g = pow((pixel[1] + 0.055)/1.055, 2.4)
     if(pixel[2] < 0.04045):
         b = pixel[2]/12.92
     else:
         b = pow((pixel[2] + 0.055)/1.055, 2.4)
     X =  0.412453*r     + 0.357580*g + 0.180423 *b
     Y =  0.212671*r     + 0.715160*g + 0.072169 *b
     Z =  0.019334*r     + 0.119193*g + 0.950227 *b
     
     new_pixel = [X, Y, Z]
     self.pixel_data[(x, y)] = new_pixel
     
     
     if(x == 0 and y == 0):
         print str(pixel[0]) + "," + str(pixel[1]) + "," + str(pixel[2])
         print self.pixel_data[(x, y)]
         
     return new_pixel
开发者ID:ohaicristina,项目名称:viv-website,代码行数:26,代码来源:VIVImage.py

示例3: weighted_mean

 def weighted_mean(self, data_array, error_array, error_0):
     '''
     weighted mean of an array        
     '''
     sz = len(data_array)
         
     # calculate the numerator of mean
     dataNum = 0;
     for i in range(sz):
         if (error_array[i] == 0):
             error_array[i] = error_0
             
         tmpFactor = float(data_array[i]) / float((pow(error_array[i],2)))
         dataNum += tmpFactor
     
     # calculate denominator
     dataDen = 0;
     for i in range(sz):
         if (error_array[i] == 0):
             error_array[i] = error_0
         tmpFactor = 1./float((pow(error_array[i],2)))
         dataDen += tmpFactor
 
     if dataDen == 0:
         data_mean = np.nan
         mean_error = np.nan
     else:            
         data_mean = float(dataNum) / float(dataDen)
         mean_error = math.sqrt(1/dataDen)     
 
     return [data_mean, mean_error]        
开发者ID:JeanBilheux,项目名称:RefRed,代码行数:31,代码来源:reduction_quicknxs.py

示例4: prove_decryption

    def prove_decryption(self, ciphertext):
        """
        given g, y, alpha, beta/(encoded m), prove equality of discrete log
        with Chaum Pedersen, and that discrete log is x, the secret key.

        Prover sends a=g^w, b=alpha^w for random w
        Challenge c = sha1(a,b) with and b in decimal form
        Prover sends t = w + xc

        Verifier will check that g^t = a * y^c
        and alpha^t = b * beta/m ^ c
        """
        
        m = (Utils.inverse(pow(ciphertext.alpha, self.x, self.pk.p), self.pk.p) * ciphertext.beta) % self.pk.p
        beta_over_m = (ciphertext.beta * Utils.inverse(m, self.pk.p)) % self.pk.p

        # pick a random w
        w = Utils.random_mpz_lt(self.pk.q)
        a = pow(self.pk.g, w, self.pk.p)
        b = pow(ciphertext.alpha, w, self.pk.p)

        c = int(sha.new(str(a) + "," + str(b)).hexdigest(),16)

        t = (w + self.x * c) % self.pk.q

        return m, {
            'commitment' : {'A' : str(a), 'B': str(b)},
            'challenge' : str(c),
            'response' : str(t)
          }
开发者ID:digitaldragoon,项目名称:referenda,代码行数:30,代码来源:algs.py

示例5: find_substep

    def find_substep(target, source, value, step_size, error):
        # recursive end condition
        if step_size < 0.0001:
            # new_source = source[:]
            # substep_shift(new_source, value)
            # return new_source
            return value

        # check plus shift
        source_plus = source[:]
        substep_shift(source_plus, value + step_size)
        p_error = 0
        for vals in zip(target, source_plus):
            p_error += pow(vals[0] - vals[1], 2)

        # check minus shift
        source_minus = source[:]
        substep_shift(source_minus, value - step_size)
        m_error = 0
        for vals in zip(target, source_minus):
            m_error += pow(vals[0] - vals[1], 2)

        # take best out of plus shift, minus shift, and no shift
        if p_error < m_error:
            if p_error < error:
                return find_substep(target, source, value + step_size, step_size / 2, p_error)
            else:
                return find_substep(target, source, value, step_size / 2, error)
        else:
            if m_error < error:
                return find_substep(target, source, value - step_size, step_size / 2, m_error)
            else:
                return find_substep(target, source, value, step_size / 2, error)
开发者ID:science-of-imagination,项目名称:Visuo,代码行数:33,代码来源:sim2NotSavingExamplar_Train11.py

示例6: generate_detail

def generate_detail(level,map):
	global iterations
	pow_max = pow(2,iterations) # 4 4 
	pow_size = pow(2,iterations-level) # 4 2 
	
	#diamond step
	for i in range(int(pow_max / pow_size)): # 0 , 0 1
		for d in range(int(pow_max / pow_size)): # 0 , 0 1
			h = 0
			x = 0
			y = 0
			print("diamond")
			for u in range(2):
				for v in range(2):
					tx = int(i * pow_size + u*pow_size)
					ty = int(d * pow_size + v*pow_size)
					print(tx," ",ty)
					h += map[tx][ty]
					y += pow_size
		
				x += pow_size
			h = h / 4 + random.uniform(0.0,100.0/(level +1))
			map[int(i*pow_size+pow_size/2)][int(d*pow_size+pow_size/2)] = h
		
	#square step
	#for i in range(int(pow_max / (pow_size/2))): # 2 , 
	
	#return(map)
	print("==level" , level , "configuration==")
	render_map(map,0,0)
	print("==level", level,"configuration==")
	if(iterations == level + 1):
		return(map)
	else:
		return(generate_detail(level+1,map))
开发者ID:pez2001,项目名称:Stuff,代码行数:35,代码来源:diamond_square.py

示例7: _try_composite

def _try_composite(a, d, n, s):
    if pow(a, d, n) == 1:
        return False
    for i in range(s):
        if pow(a, 2**i * d, n) == n-1:
            return False
    return True # n  is definitely composite
开发者ID:BeniaminK,项目名称:hackerrank_project_euler,代码行数:7,代码来源:_50_consecutive_prime_sum.py

示例8: computeDistance

def computeDistance(m1,m2):
	r = numpy.dot(m1.transpose(),m2)
	#print r
	trace = r.trace()
	s = (trace-1.0)/2.0
	if int(round(abs(s),7)) == 1:
		"""
		Either:
		 (1) Vectors are the same , i.e. 0 degrees
		 (2) Vectors are opposite, i.e. 180 degrees
		"""
		diff = numpy.sum(pow((m1-m2),2))
		#apDisplay.printWarning("overflow return, diff="+str(diff)+" m1="+str(m1)+" m2="+str(m2))
		if diff < 1.0e-6:
			return 0.0
		return 180.0
	else:
		#print "calculating"
		theta = math.acos(s)
		#print 'theta',theta
		t1 = abs(theta/(2*math.sin(theta)))
		#print 't1',t1
		t2 = math.sqrt(pow(r[0,1]-r[1,0],2)+pow(r[0,2]-r[2,0],2)+pow(r[1,2]-r[2,1],2))
		#print 't2',t2, t2*180/math.pi
		dist = t1 * t2
		dist *= 180.0/math.pi
		#print 'dist=',dist
		return dist
开发者ID:leschzinerlab,项目名称:myami-3.2-freeHand,代码行数:28,代码来源:apEulerCalc.py

示例9: findMainObject

def findMainObject(objectsCNT,shape,img=0):
    '''
     znajduje obiekt najbardziej po srodku plaszczyzny (bo to nie beda krawedzie lustra)
    '''

    #srodek obrazu
    yc0 = shape[0]/2
    xc0 = (shape[1]/4)*3

    min_index = -1
    min_cost = shape[0]*shape[1]

    marker = False

    for n,c in enumerate(objectsCNT):
        moments = cv2.moments(c)
        # policzenie srodkow ciezkosci figur
        yc = int(moments['m01']/moments['m00'])
        xc = int(moments['m10']/moments['m00'])

        #odległosc od srodka
        dx = xc0-xc
        dy = yc0-yc
        cost = sqrt(pow(dx,2)+pow(dy,2))

        if cost.real < min_cost:
            min_cost = cost.real
            min_index = n
    mainCNT = objectsCNT[min_index]

    return mainCNT
开发者ID:hasin89,项目名称:mgr,代码行数:31,代码来源:trackFeatures.py

示例10: getProfile

 def getProfile(self, r):
         
     P=0.
     if (r<self.rcut):
         P = pow(1. + (r/self.rcore)*(r/self.rcore),-0.5) - \
             pow(1. + (self.rcut/self.rcore)*(self.rcut/self.rcore),-0.5)
     return P
开发者ID:CosmoAZ,项目名称:cosmothon,代码行数:7,代码来源:simclusterfield.py

示例11: goExForceF3d

def goExForceF3d():
  sig,sig1,sig2=1,4,4
  fx = readImage(fxfile)
  ws = zerofloat(n1,n2)
  gs = zerofloat(n1,n2,2)
  gvf = GradientVectorFlow()
  ed = gvf.applyForEdge(sig,sig1,sig2,fx)
  et = gvf.applyForGVX(sig,sig1,sig2,ed,gs,ws) #channel 1
  #gvf.setScale(0.01)
  gvf.setScale(0.0)
  wp = pow(ed,1.0)
  ws = pow(ws,1.0)
  wm = pow(wp,1)
  wm = div(wm,max(wm))
  wm = sub(1,wm)
  fs = gvf.applyForGVF(None,gs[0],gs[1],ws,wm)
  writeImage(edfile,ed)
  writeImage(f1file,fs[0])
  writeImage(f2file,fs[1])
  plot(fx)
  plot(wp)
  plot(ws)
  plot(wm)
  plotVectors(10,5,gs[0],gs[1],fx)
  plotVectors(100,5,fs[0],fs[1],fx)
开发者ID:Jookai,项目名称:xmw,代码行数:25,代码来源:dave.py

示例12: sim_pearson

def sim_pearson(prefs, p1, p2):
	# Get the list of mutually rated items
	si = {}
	for item in prefs[p1]:
		if item in prefs[p2]: si[item] = 1

	n = len(si)
	if 0==n: return 0

	# Add up all the preferences
	sum1 = sum(prefs[p1][it] for it in si)
	sum2 = sum(prefs[p2][it] for it in si)

	# Sum up the squares
	sum1Sq = sum([pow(prefs[p1][it], 2) for it in si])
	sum2Sq = sum([pow(prefs[p2][it], 2) for it in si])

	pSum = sum([prefs[p1][it] * prefs[p2][it] for it in si])

	num = pSum - (sum1*sum2/n)
	den = sqrt((sum1Sq-pow(sum1, 2)/n)*(sum2Sq-pow(sum2,2)/n))
	if 0==den: return 0

	r = num/den

	return r
开发者ID:wuhy80,项目名称:PythonCode,代码行数:26,代码来源:chap1_recommendations.py

示例13: rd

def rd (tokeniser):
	try:
		value = tokeniser()

		separator = value.find(':')
		if separator > 0:
			prefix = value[:separator]
			suffix = int(value[separator+1:])

		# XXX: FIXME: we need much more checks here instead that the blank try/except...

		if '.' in prefix:
			bytes = [chr(0),chr(1)]
			bytes.extend([chr(int(_)) for _ in prefix.split('.')])
			bytes.extend([chr(suffix>>8),chr(suffix&0xFF)])
			rd = ''.join(bytes)
		else:
			number = int(prefix)
			if number < pow(2,16) and suffix < pow(2,32):
				rd = chr(0) + chr(0) + pack('!H',number) + pack('!L',suffix)
			elif number < pow(2,32) and suffix < pow(2,16):
				rd = chr(0) + chr(2) + pack('!L',number) + pack('!H',suffix)
			else:
				raise ValueError('invalid route-distinguisher %s' % value)
	except ValueError:
		raise ValueError('invalid route-distinguisher %s' % value)

	return RouteDistinguisher(rd)
开发者ID:PowerDNS,项目名称:exabgp,代码行数:28,代码来源:parser.py

示例14: try_composite

 def try_composite(a):
     if pow(a, d, n) == 1:
         return False
     for i in xrange(s):
         if pow(a, 2**i * d, n) == n - 1:
             return False
     return True
开发者ID:Deddryk,项目名称:projecteulerv2,代码行数:7,代码来源:primes.py

示例15: prime

def prime(a, q, k, n):
	if pow(a, q, n) == 1:
		return True
	elif (n - 1) in [pow(a, q*(2**j), n) for j in range(k)]:
		return True
	else:
		return False
开发者ID:812653525,项目名称:learntosolveit,代码行数:7,代码来源:algorithm_pyrsa.py


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