How to convert .mat file in binary format to python dictionary?

Viewed 323

I have a .mat file that is in memory as fileInstance by running the following:

with open(filePath, 'r+b') as FID: 
    fileInstance = FID.read()
    self.fileInstance = fileInstance

It is a binary string b" ".

I know there is :

import scipy.io
mat_dictionary = scipy.io.loadmat('myFile.mat')

However, I don't want to save to disk and then have to read it again. It is possible but very inefficient given that it is already in memory.

I have taken a look at scipy.io.loadmat and have tried to replicate a similar process. But it didn't work. If you look at the source code, it is expecting a file descriptor to the mat file. When I passed in my bytes object, it said seek() was not found. I tried to use it with the function : MatFile4Reader.

So, how can I take a mat file in memory and bytes format to a python dictionary?

0 Answers
Related