Matlab typecast transfer to python 3.7

252 Views Asked by At

I have some excerpt code for Matlab. I want to transfer to python3.7 code. But I found out some Matlab function I can not transfer to python 3.7 it, such as function typecast, and single in Matlab. Therefore, How could I write the python code and get the same result? Thank you

Here is the Matlab code

AA= uint32(3249047552)
DPD = typecast(AA,'single');    
Print(DPD)

DPD = -21.0664 <== This is matlab result.

1

There are 1 best solutions below

0
On

With numpy you can use view():

# Define your uint32 number
x = np.array(3249047552, dtype=np.uint32)
# Get the equivalent bitwise single number
x.view(np.single)
# output: -21.066406