本文整理汇总了Python中math.trunc函数的典型用法代码示例。如果您正苦于以下问题:Python trunc函数的具体用法?Python trunc怎么用?Python trunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了trunc函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mw_cdf
def mw_cdf(x_hist_vals, hist_vals, a_coeff, figs, plot=False):
max_a = np.sum(hist_vals)
area_a = np.ones(len(hist_vals))
for el in xrange(len(hist_vals)):
area_a[el] = np.sum(hist_vals[0:el+1])
c_d_f = area_a/max_a
interp = interp1d(c_d_f, x_hist_vals)
a_best = interp(0.5)
a_limits = interp(np.array([0.5 - 0.683/2.0, 0.5 + 0.683/2.0]))
decim = [math.trunc(np.abs(np.log10(a_best - a_limits[0])))+2, math.trunc(np.abs(np.log10(a_limits[1] - a_best)))+2]
uncertainties = np.array([round(a_best - a_limits[0], decim[0]), round(a_limits[1] - a_best, decim[1])])
if plot:
plt.figure(figs)
figs += 1
plt.clf()
plt.scatter(x_hist_vals, c_d_f, marker='+')
plt.plot((a_best, a_best), (( c_d_f.max(), 0)), 'g')
plt.errorbar(a_best, 0.5, xerr=[[uncertainties[0]], [uncertainties[1]]], fmt='^', color='red')
plt.ylabel('CDF ')
plt.xlabel(r'a$_'+str(a_coeff)+'$ values')
plt.title(r'Result: a$_'+str(a_coeff)+' = '+str(round(a_best, np.max(decim)))+'_{-'+str(uncertainties[1])+'}^{+'+str(uncertainties[0])+'}$')
plt.show() #in most cases unnecessary
return figs
示例2: muestraAccel
def muestraAccel(self):
wiiuse.motion_sensing(self.wiimotes,self.nmotes)
wiiuse.poll(self.wiimotes, self.nmotes)
t = self.wm.gforce.x
temp=0
try:
temp = math.trunc(t)
except:
temp=0
if temp< (self.rotX-3) or temp> (self.rotX+3):
self.rotX= temp
self.window.emit(SIGNAL("AccelX"), self.rotX)
t = self.wm.gforce.y
temp=0
try:
temp = math.trunc(t)
except:
temp=0
if temp < (self.rotY-3) or temp > (self.rotY+3):
self.rotY= temp
self.window.emit(SIGNAL("AccelY"), self.rotY)
t = self.wm.gforce.z
temp=0
try:
temp = math.trunc(t)
except:
temp=0
if temp != self.rotZ:
self.rotZ= temp
self.window.emit(SIGNAL("AccelZ"), self.rotZ)
示例3: test_something_typeConversions
def test_something_typeConversions(self):
import math
self.assertEqual(complex(1), complex(Something(1)))
self.assertEqual(oct(1), oct(Something(1)))
self.assertEqual(hex(16), hex(Something(16)))
self.assertEqual(math.trunc(math.pi), math.trunc(maybe(math.pi)))