Exact value of hard code float values ​​in Python

advertisements

This is probably overkill for my problem, but I am curious about the answer.

I have a matrix of np.float32 values that I want to put into some code. It's 50x3 so I want to just put it in the source directly - it's not something that will change often. It's a little sensitive to rounding, so I want to encode the data exactly if possible. Is there a good way to do this in the source while also preserving the matrix format?

I'm thinking something along the lines of putting [[0xC45B36F3, ...],...] and somehow encoding that to a np.float32.


If you chose to encode the integer values, you could then do:

int_data = np.array([[0xC45B36F3, ...],...], dtype=np.uint32)
floats = int_data.view(np.float32)