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


Python Timer.print_update方法代码示例

本文整理汇总了Python中timer.Timer.print_update方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.print_update方法的具体用法?Python Timer.print_update怎么用?Python Timer.print_update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在timer.Timer的用法示例。


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

示例1: save

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import print_update [as 别名]
    def save(self,file):
        """
            Arguments:
                
                file: where to save (utf-8 encoding)

            Examples:
                
                ngrams.save("myfile")
        """

        file = self.__test_file(file,'w')
        n_word = len(self)

        buffer = ""

        sys.stderr.write("Saving the %i-grams...\n" % self.__max_arity)

        t = Timer(n_word,out=sys.stderr)
        t.start()
        for i in range(self.__max_arity):
            for word in self.__get_sorted_grams(i,(0,i+1)):
                buffer += "#".join(word)+"%"+str(self.__ngrams[i][word])+"\n"

                if len(buffer) > 1000:
                    file.write(buffer)
                    buffer = ""

                t.print_update(1)

        file.write(buffer)
        file.close()
开发者ID:bouthilx,项目名称:toiledemots,代码行数:34,代码来源:ngrams.py

示例2: save_dataset

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import print_update [as 别名]
def save_dataset(X,y,file_path):
    print "saving extended dataset..."
    print "saving %d images..." % X.shape[0]

    f = open(file_path,"w")
    z = zip(X,y)
    np.random.shuffle(z)
    t = Timer(X.shape[0])
    t.start()
    for X, y in z:
        f.write("%d,\"%s\"\n" % (np.int(np.argmax(y)), " ".join([str(i) for i in X.flatten().astype(int)])))
        t.print_update(1)
    f.close()
    print "it took",seconds_to_string(t.over())
开发者ID:Kerkil,项目名称:ift6266kaggle,代码行数:16,代码来源:__init__.py

示例3: build

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import print_update [as 别名]
    def build(self,lines,clean_str=u'[!"%&\'\(\)\+,‚‘’\.\/:;=?\[\]«»¡£§²´µ·¸º°…“”•„−–—]',del_lines=False):
        """
            Arguments:
                
                lines: the lines to build the n-grams
                clean_str: a regular expression to clean the strings (default removes every special characters)

            Example:

                ngrams = nGrams(3)
                ngrams.build([u"C'est un test bien simple",u"Ça ne fait pas beaucoup de mots","est ce bien?"])
        """

        self.__len = 0
        self.__nlen = [0 for i in range(self.__max_arity)]

        sys.stderr.write("Building the %i-grams...\n" % self.__max_arity)
        n_lines = len(lines)
        n_buffer = self.__init_buffer() 

        t = Timer(n_lines,out=sys.stderr)
        t.start()
        for line in lines:

            line = line.lower().strip(u'\n')

            if clean_str:
                line = re.sub(clean_str, ' ', line)

            n_buffer = self.__init_buffer()

            for word in line.split(" "):
                word = word.strip(" ")#word.strip("-").strip(" ")

                if word:
                    n_buffer = self.__update_buffer(n_buffer,word)

            self.__empty_buffer(n_buffer)
                        
            t.print_update(1)
            
            del lines[0]

        sys.stderr.write("Sorting the %i-grams...\n" % self.__max_arity)

        len(self)
 
        for ng in range(self.__max_arity):
            self.__sort_keys(ng,(0,ng+1))
开发者ID:bouthilx,项目名称:toiledemots,代码行数:51,代码来源:ngrams.py

示例4: load

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import print_update [as 别名]
    def load(self,file):
        """
            Arguments:
                
                file: file to build the n-grams

            Examples:
                
                ngrams.load("myfile")
        """

        file = self.__test_file(file,'r')
        self.__ngrams = []
        self.__sorted_grams = []
        lines = file.readlines()
        file.close()
        n_lines = len(lines)

        self.__len = 0
        self.__nlen = [0 for i in range(self.__max_arity)]

        sys.stderr.write("Loading the %i-grams...\n" % self.__max_arity)

        t = Timer(n_lines,out=sys.stderr)
        t.start()
        for line in lines:
            word, count = line.split("%")
            word = word.split("#")
            n_grams = len(word)-1

            if n_grams > self.__max_arity-1:
                break
        
            while len(self.__ngrams) <= n_grams:
                self.__ngrams.append({})
                self.__sorted_grams.append({(0,n_grams+1):[]})
                
            self.__ngrams[n_grams][tuple(word)] = int(count)
            self.__get_sorted_grams(n_grams,(0,n_grams+1)).append(tuple(word))
            
            t.print_update(1)

        self.__max_arity = len(self.__ngrams)

        # to calculate and store __len and __nlen
        len(self)
开发者ID:bouthilx,项目名称:toiledemots,代码行数:48,代码来源:ngrams.py


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