pythonfloating-pointuint16

how to present uint16 as float16


I have a buffer of float16 elements in the memory I read this buffer to a list but since I use np.ctypeslib I can't read it as float16 so I read it as uint16 and now I want to represent it as float16

simple convert by list.astype(float16) won't help I found this table https://gist.github.com/gregcotten/9911bda086c5850cb513b2980cca7648 and according to that table it works.

I want to write a python function for convention unint16_as_float16 but don't know what are the rules.

appreciate your help thanks!


Solution

  • I found a solution by numpy

    uint16_list.view(np.float16)