I am saving a structured numpy array of the to a mat file using scipy.io.savemat this way:
sio.savemat(filename, { ‘myStructuredArray’: myStructuredArray}, appendmat=True )
then I reload it this way:
mat = sio.loadmat( filename, squeeze_me=True) # mat actually contains additional variables not shown here
myStucturedArray = mat['myStucturedArray']
The content of the reloaded array is correct but the dtype of the reloaded array has changed.
Before saving dtype looks like this:
[('time', '<f8'), ('eType', '<i8'), ('name', 'S10')]
but after reload it looks like this instead:
[('time', 'O'), ('eType', 'O'), ('name', 'O')]
therefore when I subsequently try to append further structured data ( of form [('time', '<f8'), ('eType', '<i8'), ('name', 'S10')]) to that reloaded array python throws the following error:
TypeError: invalid type promotion with structured datatype(s).
How can i make sure that dtypes are preserved when I use savemat?