def unhashfloat128(x,N):
'''
Unpack bits from number b; inverse of `hashbits()`
Not to be confused with `pylab.unpackbits`
Parameters
----------
x : float128
integer stored in float128, whose binary bits match x
N : positive integer, number of bits in each vector
Returns
-------
b : boolean or binary vector, unpacked
'''
if not x.dtype==np.float128:
raise ValueError('Expected to unpack bit data from np.float128')
x = x.copy()
b = []
for i in range(N):
b.append(x%2)
x = np.floor(x*0.5)
b = (np.uint8(b)==1)
return b.T
评论列表
文章目录