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


Python Math类代码示例

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


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

示例1: overtones_to_equalizer

    def overtones_to_equalizer(self, control, semitone, overtones=10):
        if not self.project:
            return

        x = self.project.pipeline.eq.frequencies
        y = self.project.pipeline.eq.props.transmission

        fundamental_frequency = Math.semitone_to_frequency(semitone)

        for overtone in xrange(overtones + 1):
            frequency = fundamental_frequency * (overtone + 1)
            semitone = Math.frequency_to_semitone(frequency)

            lower = Math.semitone_to_frequency(semitone - 0.5)
            upper = Math.semitone_to_frequency(semitone + 0.5)

            if lower > x[-1]:
                break

            for i in xrange(len(x)):
                if x[i] > upper:
                    break

                if lower <= x[i]:
                    y[i] = 1.0

        self.project.pipeline.eq.props.transmission = y
开发者ID:Leberwurscht,项目名称:Python-Guitar-Transcription-Aid,代码行数:27,代码来源:transcribe.py

示例2: analyze_overtones

	def analyze_overtones(self,semitone,overtones=None):
		""" calculates power and peak center for each overtone and yields tuples (overtone, frequency, power, peak_center, difference_in_semitones) """
		frequency = Math.semitone_to_frequency(semitone)
		peak_radius = self.get_peak_radius()

		overtone=0

		while overtones==None or overtone<overtones:
			f = frequency*(overtone+1)
			s = Math.frequency_to_semitone(f)

			lower_frequency = f - peak_radius*1.65
			upper_frequency = f + peak_radius*1.65

			lower_frequency = min(lower_frequency, Math.semitone_to_frequency(s-0.5))
			upper_frequency = max(upper_frequency, Math.semitone_to_frequency(s+0.5))

			power = self.get_power_in_frequency_range(lower_frequency,upper_frequency)
			peak_center = self.get_powerfreq_spline().integral(lower_frequency,upper_frequency) / power

			difference_in_semitones = Math.frequency_to_semitone(peak_center) - s

			yield overtone, f, power, peak_center, difference_in_semitones

			overtone += 1
开发者ID:Leberwurscht,项目名称:Python-Guitar-Transcription-Aid,代码行数:25,代码来源:VisualizerControl.py

示例3: analyze_semitone

    def analyze_semitone(self, control, semitone):
        if not self.project:
            return
        if not control.has_data:
            return

        text = ""

        for overtone, frequency, power, peak_center, difference_in_semitones in control.analyze_overtones(semitone, 10):
            s = Math.frequency_to_semitone(frequency)
            position = control.start + control.duration / 2.0
            lower = Math.semitone_to_frequency(s - 0.5)
            upper = Math.semitone_to_frequency(s + 0.5)
            onset_min, onset_max = self.project.appsinkpipeline.find_onset(lower, upper, position, limit=5)
            text += "%d. overtone: %f Hz (semitone %f; near %s)\n" % (overtone, frequency, s, Math.note_name(s))
            text += "\tPower: %f (%f dB)\n" % (power, Math.power_to_magnitude(power))
            text += "\tPosition: %f Hz (off by %f semitones)\n" % (peak_center, difference_in_semitones)
            text += "\tOnset: between %fs and %fs\n" % (onset_min, onset_max)
            text += "\n"

        w = gtk.Window()
        w.set_size_request(500, 400)
        w.set_title("Info on %s (%f)" % (Math.note_name(semitone), semitone))

        sw = gtk.ScrolledWindow()
        w.add(sw)

        tv = gtk.TextView()
        tv.get_buffer().set_text(text)
        tv.set_editable(False)
        sw.add(tv)

        w.show_all()
开发者ID:Leberwurscht,项目名称:Python-Guitar-Transcription-Aid,代码行数:33,代码来源:transcribe.py

示例4: guessing_game

def guessing_game():
	'''finish this. idea: want to calculate optimal cost C(10^12, sqrt{k}, sqrt{F_k}) where F_k is the k-th fibonacci number;
	this means that the cost for overshooting the hidden number n in range(1,10^12) is much higher than the cost for undershooting
	(or is it vice versa? check the rules.)... hence we should bias towards the low end by a factor given by a function of (k,F_k).
	Idea: biased binary search?'''
	result = 0.0
	for k in range(1,30):
		result += calculate_optimal_worst_case_cost(10**12, Math.sqrt(k), Math.sqrt((phi**k - ((-phi)**(-k))) / Math.sqrt(5)))
	print result
开发者ID:paulswtang,项目名称:p-e-solutions,代码行数:9,代码来源:ProjectEulerPt1.py

示例5: vis_plot_evolution

    def vis_plot_evolution(self, viscontrol, semitone):
        if not self.project:
            return

        playback_marker = self.project.timeline.ruler.get_playback_marker()
        if not playback_marker:
            return

        import scipy.interpolate

        start, duration = playback_marker

        ##########
        dialog = gtk.Dialog(
            title="interval",
            flags=gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL,
            buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT),
        )
        entry = gtk.Entry()
        entry.set_text("0.1")
        dialog.vbox.add(entry)
        dialog.show_all()
        dialog.run()
        interval = float(entry.get_text())
        dialog.destroy()
        #############

        # 		interval = 0.1
        delta = interval / 2.0
        steps = 1.0 * duration / delta

        x = []
        y = []
        for step in xrange(int(steps)):
            pos = start + step * delta
            frq, power = self.project.appsinkpipeline.get_spectrum(pos - interval / 2.0, pos + interval / 2.0)
            # 			frq, power = self.project.appsinkpipeline.get_spectrum(pos,pos+interval)

            spline = scipy.interpolate.InterpolatedUnivariateSpline(frq, power, None, [None, None], 1)

            lower = Math.semitone_to_frequency(semitone - 0.5)
            upper = Math.semitone_to_frequency(semitone + 0.5)
            total = spline.integral(lower, upper)

            x.append(pos)
            y.append(total)

        w = Analyze.Analyze()
        w.show_all()
        w.simple_plot(x, y)
开发者ID:Leberwurscht,项目名称:Python-Guitar-Transcription-Aid,代码行数:50,代码来源:transcribe.py

示例6: setGrowthVolumePerDayRelVolume

 def setGrowthVolumePerDayRelVolume(self, multiple):
     '''
     Set the growth volume per day relative to the maximum cell volume.
     :param multiple: Factor for the daily growth.
     :return:
     '''
     self.growthVolumePerDay = multiple * Math.calcSphereVolumeFromDiameter(self.maxDiameter)
开发者ID:informatik-mannheim,项目名称:Moduro-CC3D,代码行数:7,代码来源:CellType.py

示例7: press_semitone

	def press_semitone(self,semitone,target,event,string,fret):
		if event.button==1:
			self.pipeline.get_by_name("volume").set_property("volume", self.volume.get_value())
			self.pipeline.get_by_name("src").set_property("freq", Math.semitone_to_frequency(semitone.semitone))
			self.pipeline.set_state(gst.STATE_PLAYING)
		elif event.button==3:
			self.open_context_menu(semitone,event,string,fret)
开发者ID:Leberwurscht,项目名称:Python-Guitar-Transcription-Aid,代码行数:7,代码来源:Visualizer.py

示例8: get_spectrum

    def get_spectrum(self, start, stop):
        data = self.get_data(start, stop)
        if not len(data) > 0:
            return numpy.array([]), numpy.array([])

        rate = self.caps[0]["rate"]

        samples = min(MAX_FFT_SAMPLES, len(data))  # number of data points to consider for each fft

        ffts = len(data) / int(samples / 2.0) - 1  # number of ffts

        # calculate average over powers
        power = 0.0

        for i in xrange(ffts):
            shift = int(0.5 * i * samples)
            power += Math.windowed_fft(data[shift : shift + samples])

        power /= ffts

        # calculate frequencies
        bands = len(power)
        frq = 0.5 * (numpy.arange(bands) + 0.5) * rate / bands

        return frq, power
开发者ID:Leberwurscht,项目名称:Python-Guitar-Transcription-Aid,代码行数:25,代码来源:Pipeline.py

示例9: __init__

 def __init__(self,id,s1,s2): #Arrête de s1 vers s2
     self.id = id
     self.sommet1 = s1
     self.sommet2 = s2
     self.length = Math.sqrt((s1.x-s2.x)**2+(s1.y-s2.y)**2)
     self.pop = 0 #Combien d'unités parcourent cette arrête
     self.owner = None #Qui possède ces unités
开发者ID:Lanchoe,项目名称:LSLW,代码行数:7,代码来源:Game.py

示例10: get_next_move_to

	def get_next_move_to(self, position, final_target):
		"""Get the next point an agent following this path should move to.

		Reference: Simple Stupid Funnel Algorithm
		http://digestingduck.blogspot.com/2010/03/simple-stupid-funnel-algorithm.html

		@type position: Vector
		@param position: The position of the agent following the path
		"""

		current_polys = [] 
		for poly in self._polygons:
			if poly.contains_point(position):
				current_polys.append(poly)

		i = max((self._polygons.index(p) for p in current_polys))
		
		if i == len(self._polygons)-1: return final_target

		edge = self._polygons[i].neighbors[self._polygons[i+1]][1]
		
		left, right = (edge[0], edge[1]) if Math.point_orientation(position, edge[0], edge[1]) else (edge[1], edge[0])

		for j in range(i+1, len(self._polygons)-1):
			edge = self._polygons[j].neighbors[self._polygons[j+1]][1]
			new_left, new_right = (edge[0], edge[1]) if Math.point_orientation(position, edge[0], edge[1]) else (edge[1], edge[0])
		
			# make the funnel smaller
			if Math.point_orientation(position, left, new_left): left = new_left
			if not Math.point_orientation(position, left, right): 
				return right
			
			
			if not Math.point_orientation(position, right, new_right): right = new_right
			if not Math.point_orientation(position, left, right): 
				return left

		if Math.point_orientation(position, left, final_target): left = final_target
		if not Math.point_orientation(position, left, right):
			return right

		if not Math.point_orientation(position, right, final_target): right = final_target
		if not Math.point_orientation(position, left, right):
			return left

		return final_target
开发者ID:tartley,项目名称:Py2D,代码行数:46,代码来源:Navigation.py

示例11: do_simple_paint

	def do_simple_paint(self, cr, bounds):
		cr.translate(self.x, self.y)
		cr.rectangle(0.0, 0.0, self.width, self.height)

		if not self.control.has_data:
			cr.set_source_rgb(1.,1.,1.)
		elif self.method=="cumulate":
			fpower, power, center, standard_deviation, upper_dependence, lower_dependence = self.control.analyze_semitone(self.semitone)
			magnitude = Math.power_to_magnitude(power / 1.5 / 1000)
			const,slope = self.control.get_brightness_coefficients_for_magnitude()
			brightness = slope*magnitude + const
			print self.semitone,"mag",magnitude,"tpow",power,"b",brightness,"pow",fpower
			cr.set_source_rgb(brightness,brightness,brightness)
		elif self.method=="test":
			fpower, power, center, standard_deviation, upper_dependence, lower_dependence = self.control.analyze_semitone(self.semitone)
			upper_dependence = min(1.,upper_dependence)
			lower_dependence = min(1.,lower_dependence)
			total_dependence = min(1., upper_dependence+lower_dependence)
			power *= 1. - total_dependence
			magnitude = Math.power_to_magnitude(power / 1.5 / 1000)
			const,slope = self.control.get_brightness_coefficients_for_magnitude()
			brightness = slope*magnitude + const
			cr.set_source_rgb(brightness,brightness,brightness)
		elif self.method=="inharmonicity":
			fpower, power, center, standard_deviation, upper_dependence, lower_dependence = self.control.analyze_semitone(self.semitone)
			brightness = standard_deviation / 0.5
			cr.set_source_rgb(brightness,brightness,brightness)
		elif self.method=="lower_dependence":
			fpower, power, center, standard_deviation, upper_dependence, lower_dependence = self.control.analyze_semitone(self.semitone)
			brightness = lower_dependence
			cr.set_source_rgb(brightness,brightness,brightness)
		elif self.method=="upper_dependence":
			fpower, power, center, standard_deviation, upper_dependence, lower_dependence = self.control.analyze_semitone(self.semitone)
			brightness = upper_dependence
			cr.set_source_rgb(brightness,brightness,brightness)
		elif self.method=="gradient":
			assert not self.matrix==None
			gradient = self.control.get_gradient()
			gradient.set_matrix(self.matrix)
			cr.set_source(gradient)
		else:
			raise ValueError, "Invalid method"

		cr.fill_preserve()
		cr.set_source_rgb(0.,0.,0.)
		cr.stroke()
开发者ID:Leberwurscht,项目名称:Python-Guitar-Transcription-Aid,代码行数:46,代码来源:Visualizer.py

示例12: find_onset

    def find_onset(self, viscontrol, semitone):
        if not self.project:
            return

        playback_marker = self.project.timeline.ruler.get_playback_marker()
        if not playback_marker:
            return

        start, duration = playback_marker

        position = start + duration / 2.0

        lower = Math.semitone_to_frequency(semitone - 0.5)
        upper = Math.semitone_to_frequency(semitone + 0.5)

        onset, onset_max = self.project.appsinkpipeline.find_onset(lower, upper, position)

        self.project.timeline.ruler.set_playback_marker(onset, start + duration - onset)
开发者ID:Leberwurscht,项目名称:Python-Guitar-Transcription-Aid,代码行数:18,代码来源:transcribe.py

示例13: __init__

	def __init__(self, control, tuning=-5, **kwargs):
		FretboardWindowBase.__init__(self, **kwargs)

		self.set_title("Undertones of %s-tuned string (%f - %f Hz)" % (Math.note_name(tuning), tuning, Math.semitone_to_frequency(tuning)))

		root = self.canvas.get_root_item()
		self.visualizer = Undertones(control, self.volume, parent=root, tuning=tuning)

		self.adjust_canvas_size()
开发者ID:Leberwurscht,项目名称:Python-Guitar-Transcription-Aid,代码行数:9,代码来源:Visualizer.py

示例14: updateOrientation

def updateOrientation(rotation):
    from bge.logic import getCurrentController
    import mathutils
    import Math
    
    blendrot = Math.convertOrientation(rotation)

    controller = getCurrentController()
    obj = controller.owner
    obj.orientation = blendrot
开发者ID:Alexanderallenbrown,项目名称:MotionBase,代码行数:10,代码来源:OSVR-Blender-addon.py

示例15: classficition

def classficition(features_path, save_path, picture_path, suff=".bmp"):
    # 标志序列,0表示没有比对过的,1表示已经比对过的
    if not os.path.exists(save_path):
        os.mkdir(save_path)
    all_num = text_process.Pic_Num(features_path, count=[0])
    mark = [0] * all_num
    file_num = 0
    dis = 0.65  # 此阈值可根据你自己需要更改

    for i in range(all_num):
        if mark[i] != 0:
            continue
        else:
            mark[i] = 1
            save_dir_name = "%s%d" % (save_path + "/", file_num)
            if not os.path.exists(save_dir_name):
                os.mkdir(save_dir_name)
            oldf_num = "%09d" % i
            oldfile_name = "%s%s%s" % (picture_path + "/", oldf_num, suff)

            newfile_name = "%s%s%09d%s" % (save_dir_name, "/", 0, suff)
            shutil.copyfile(oldfile_name, newfile_name)

            bais_feature_num = i
            bais_feature_file = "%s%09d%s" % (features_path + "/", bais_feature_num, ".txt")
            bais_features_data = text_process.load(bais_feature_file)

            j = i + 4000  # 在1000张范围内搜索
            end = Math.Min(j, all_num)
            num = 1
            count = 0
            for k in range(i + 1, end):
                if mark[k] != 0:
                    continue
                else:
                    feature_num = k
                    feature_file = "%s%09d%s" % (features_path + "/", feature_num, ".txt")
                    feature_data = text_process.load(feature_file)
                    # 计算相似度
                    sim = Math.dis_cos(np.array(bais_features_data), np.array(feature_data), 256, "false")
                    if sim < dis:
                        continue
                    else:
                        mark[k] = 1
                        count += 1
                        oldf_num = "%09d" % k
                        oldfile_name = "%s%s%s" % (picture_path + "/", oldf_num, suff)
                        newfile_name = "%s%s%09d%s" % (save_dir_name, "/", num, suff)
                        num += 1
                        shutil.copyfile(oldfile_name, newfile_name)
            if count < 10:
                shutil.rmtree(save_dir_name)
            else:
                file_num += 1
    print u"分类结束,共得到%d类" % (file_num)
开发者ID:yiboin,项目名称:Tools,代码行数:55,代码来源:ext-classficition.py


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