def test_setgetbit(): # bit-wise copy arr = numpy.array(range(256), dtype=numpy.float64) arr2 = numpy.zeros(arr.shape, dtype=arr.dtype) for i in range(arr.nbytes * 8): b = bittools.getbit(arr, i) bittools.setbit(arr2, i, b) assert (arr == arr2).all(), ` arr, arr2 ` print 'ok'
def test_setgetbit(): # bit-wise copy arr = numpy.array(list(range(256)), dtype=numpy.float64) arr2 = numpy.zeros(arr.shape, dtype=arr.dtype) for i in range(arr.nbytes * 8): b = bittools.getbit(arr, i) bittools.setbit(arr2, i, b) assert (arr==arr2).all(),repr((arr,arr2)) print('ok')
def tobinary(arr): return ''.join( [str(bittools.getbit(arr, i)) for i in range(arr.nbytes * 8)])
def tobinary(arr): return ''.join([str(bittools.getbit (arr,i)) for i in range (arr.nbytes*8)])