2021-09-18

python中 uint32与float32相互转换

# float32转成uint32
def float_to_int():
    for _ in range(50000):
        n = random.uniform(-1000, 1000)
        number_array = numpy.array([n, ], numpy.float32)
        number_array.dtype = numpy.uint32
        return [number for number in number_array]
 

# uint32转成float32
def int_to_float():
    number_array = numpy.array([-2.0, 8.25], numpy.float32)
    number_array.dtype = numpy.uint32
    return [number for number in number_array]

你可能感兴趣的:(python)