I have a byte array, which originally was converted from a float array in Scala. I need to convert it back to a float array in Python.
This is the code I used to convert the float array in Scala:
val float_ary_len = float_ary.size
val bb = java.nio.ByteBuffer.allocate(float_ary_len * 4)
for(each_float <- float_ary){
bb.putFloat(each_folat)
}
val bytes_ary = bb.array()
Then in Python, I can get this byte array and I need to convert it back to a float array.
I have tried the following code in Python, but it didn't give me the right float.
print(list(bytes_ary[0:4]))
#['\xc2', '\xda', 't', 'Z']
struct.unpack('f', bytes_ary[0:4])
# it gave me 1.7230105268977664e+16, but it should be -109.22725
Please let me know how should I get the right float?