脚本宝典收集整理的这篇文章主要介绍了Python 中 Elias Delta 编码详情,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
语法:
Elias Delta Encoding(X)= Elias Gamma encoding (1+floor(LOG2(X)) + Binary rePResentation of X wIThout MSB.
首先,在为 Elias Delta
编码编写代码之前,我们将实现 Elias delta
编码。
log
、floor
函数以执行对数运算。Elias Gamma
中进行编码。floor
和 log
函数,找到 1+floor(log2(X)
并将其存储在变量 N 中。 (N-1)*'0'+'1'
找到 N 的一元编码,它为我们提供了一个二进制字符串,其中最低有效位为 '1',其余最高有效位为 N-1 个'0'。示例: 某些值的 Elias Gamma
编码
def EliasGammaEncode(k): if (k == 0): return '0' N = 1 + floor(log(k, 2)) Unary = (N-1)*'0'+'1' return Unary + Binary_Representation_Without_MSB(k)
MSB
。“{0:b}”.format(k)
找到 k 的二进制等效项并将其存储在名为 binary
的变量中。format()
的哪个参数来填充 {}。binary[1:]
,它是 X 的二进制表示,没有 MSB
。示例: 不带 MSB
的二进制表示
def Binary_Representation_Without_MSB(x): binary = "{0:b}".format(int(x)) binary_without_MSB = binary[1:] return binary_without_MSB
现在我们要为 Elias Delta Encoding
编写代码
Elias Delta
中进行编码。floor
和 log
函数,找到 1+floor(log2(k)
。 1+floor(log2(k)
的结果传递给 Elias Gamma
编码函数。示例:某些值的 Elias Delta
编码
def EliasDeltaEncode(x): Gamma = EliasGammaEncode(1 + floor(log(k, 2))) binary_without_MSB = Binary_Representation_Without_MSB(k) return Gamma+binary_without_MSB k = int(input('Enter a number to encode in Elias Delta: ')) print(EliasDeltaEncode(k))
MSB
的 k 的 Elias Gamma
编码和二进制表示的结果为某些整数值生成 Elias Delta
编码的完整代码
From math import log from math import floor def Binary_Representation_Without_MSB(x): binary = "{0:b}".format(int(x)) binary_without_MSB = binary[1:] return binary_without_MSB def EliasGammaEncode(k): if (k == 0): return '0' N = 1 + floor(log(k, 2)) Unary = (N-1)*'0'+'1' return Unary + Binary_Representation_Without_MSB(k) def EliasDeltaEncode(x): Gamma = EliasGammaEncode(1 + floor(log(k, 2))) binary_without_MSB = Binary_Representation_Without_MSB(k) return Gamma+binary_without_MSB k = 14 print(EliasDeltaEncode(k))
输出:
00100110
到此这篇关于Python 中 Elias Delta 编码详情的文章就介绍到这了,更多相关Python 中 Elias Delta 编码内容请搜索脚本宝典以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本宝典!
以上是脚本宝典为你收集整理的Python 中 Elias Delta 编码详情全部内容,希望文章能够帮你解决Python 中 Elias Delta 编码详情所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。