为了解释这一点,这基本上是一种将浮点向量数据压缩成具有单个公共无符号指数的8位或16位有符号或无符号整数(其中最常见的是bs16
,表示公共指数为11的精度)。在
我不确定这个伪float方法是什么;我只知道要得到结果float,您需要执行以下操作:
float_result = int_value / ( 2.0 ** exponent )
我想做的是通过从给定的浮点数中重新计算指数来匹配这些数据。 (如果处理得当,还可以用其他格式重新计算)
因此,如果我得到的是一个由1140个浮点组成的大组,我如何找到公共指数并将这些浮点转换成这种压缩的bu8
、bs8
、bu16
或{
编辑:样例
^{pr2}$编辑2: 我不会确切地称之为“压缩”,因为它实际上是一个提取的尾数,通过共享指数重新计算。在
如果有原始值和相应的结果,可以使用log来查找指数。数学有一个日志函数可以使用。您必须将Int_value/float_结果记录到基2。在
例如:
也许是这样的:
输出:
^{pr2}$当然,您可以编写一个包装器函数,它将接受一个字符串参数,例如
'bs16'
,并自动计算a
,b
编辑时:
1)如果你有确切的浮动值,以上应该行得通。它引入了任何舍入错误,您可能希望将
y == int(y)
替换为abs(y-round(y)) < 0.00001
(或类似的东西)。在2)除非原始整数列表中的所有整数均为偶数,否则第一个有效指数将是所需的指数。如果你有1140个值,并且它们在某种意义上是随机的,那么发生这种情况的可能性非常小。在
在进一步编辑时:如果所讨论的浮点不是由该过程生成的,但您希望找到一个允许对给定大小的整数进行(有损)压缩的最佳指数,您可以这样做(未经彻底测试):
要测试它:
选择公共指数11似乎是有原因的。在
相关问题 更多 >
编程相关推荐