generate_stats.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:ekphrasis 作者: cbaziotis 项目源码 文件源码
def write_stats_to_file(filename, counts, mincount):
    os.makedirs(os.path.dirname(filename), exist_ok=True)
    with open(filename + ".txt", 'w', encoding="utf-8") as f:
        if args.perc == 0:
            percentile = 0
        else:
            percentile = numpy.percentile(numpy.fromiter(counts.values(), numpy.int32), args.perc)
        threshold = max(percentile, mincount)

        for k, v in counts.items():

            if v >= threshold:
                entry = k.split(SEPARATOR)
                entry.append(str(v))
                f.write('\t'.join(entry) + '\n')

    if args.pickle:
        with open(filename + ".pickle", 'wb') as f:
            pickle.dump(counts, f)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号