【知识发现】python开源哈夫曼编码库huffman
来源:互联网 发布:哪个车票购票软件 编辑:程序博客网 时间:2024/06/03 21:46
1、哈夫曼树:
安装:pip install huffman
pypi地址:https://pypi.python.org/pypi/huffman
源码很值得参考。
2、案例:
# -*- coding: utf-8 -*-'''Created on 2017年9月26日@author: Administrator'''import huffmanimport collectionst1=huffman.codebook([('A', 2), ('B', 4), ('C', 1), ('D', 1)])print (t1)t2=huffman.codebook(collections.Counter('man the stand banana man').items())print (t2)
说明:rovided an iterable of 2-tuples in (symbol, weight) format, generate a Huffman codebook, returned as a dictionary in {symbol: code, ...} format.
3、构造哈夫曼树参考:
#构造哈夫曼树import heapqtrees=huff_df.values.T.tolist() #dataframe转化成listheapq.heapify(trees)while len(trees)>1: rightChild,leftChild=heapq.heappop(trees),heapq.heappop(trees) parentNode=(leftChild[0]+rightChild[0],leftChild,rightChild) heapq.heappush(trees,parentNode)print (trees)
huff_df是一个dataframe,转化成list,里面是结点及其频率。
阅读全文
0 0
- 【知识发现】python开源哈夫曼编码库huffman
- [python]Huffman Encoding哈夫曼编码
- 用python实现Huffman编码
- Huffman树&&Huffman编码
- huffman编码
- huffman编码
- HUFFMAN 编码
- Huffman编码
- huffman编码
- huffman编码
- Huffman编码
- Huffman编码
- Huffman编码
- Huffman编码
- HuffMan编码
- Huffman编码
- Huffman编码
- Huffman编码
- 分布式Session的几种实现方式
- 2309 BST
- 晨魅--学Struts1做easyui树形
- (三)架构的代码结构
- Hello world!
- 【知识发现】python开源哈夫曼编码库huffman
- Android自定义View——实现水波纹效果类似剩余流量球
- 罗斯基的机器学习(二)线性回归与Logistic回归
- Linux终端命令
- 重磅 | 最全PPT实录!英伟达发布可编程AI推理加速器TensorRT
- MongoDB常用指令(一)
- 剑指offer---java练习篇(1)
- 如何优雅地用TensorFlow预测时间序列:TFTS库详细教程
- Linux 命令整合