Why does saving mat files with scipy result in larger file size than with Matlab?

JoErNanO

Let's say I generate the following toy dataset from Matlab, and I save it as a mat file:

>> arr = rand(100);
>> whos arr
  Name        Size             Bytes  Class     Attributes

  arr       100x100            80000  double
>> save('arr.mat', 'arr')

The saved arr.mat file is of size 75829 Bytes according to the output of the ls command.

If I load the same file using scipy.io.loadmat() and save it again using scipy.io.savemat():

arr = io.loadmat('arr.mat')
with open('arrscipy.mat', 'w') as f:
    io.savemat(f, arr)

I obtain a file with a considerably different size (∼ 4KB larger):

$ ls -al
75829 Nov  6 11:52 arr.mat
80184 Nov  6 11:52 arrscipy.mat

I now have two binary mat files containing the same data. My understanding is that the size of a binary mat file is determined by the size of its contained variables, plus some overhead due to file headers. However the sizes of these two files are considerably different. Why is this? Is it a data format problem?

I tried this with arrays of structures too, and the result is similar: scipy-saved mat files are larger than Matlab-saved ones.

Daniel

Look at the docs:

scipy.io.savemat(file_name, mdict, appendmat=True, format='5',
    long_field_names=False, do_compression=False, oned_as='row')

Compression is turned off by default. In matlab compression is always turned on.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why does writing an image to a stream give me a different result than directly saving to a file?

Saving data to .mat file in MATLAB

Why does a numpy array with dtype=object result in a much smaller file size than dtype=int?

List files larger than {size} sorted by date

Why does winfo_width() return a larger size of button widget than the size of what it exactly looks like?

Why does shifting a value further than its size not result in 0?

Why the tuple has a larger size than expected?

Why is lineHeight of UIFont larger than font size?

Matlab saving a .mat file with a variable name

Creating a table and saving it as a .mat file in matlab

Writing a file larger than block size in hdfs

Why does this recursive function counting nodes in a binary search tree always return a result larger than expected?

How to config AEM to use local file system instead of mongoDB for files larger than a specific size?

Why does text with a larger font-size show up lower than other text and how to stop it?

Why the size of base64-encoded string is larger than the original file

Does a program, in general, have a larger file size when compiled with an IDE than saved by a normal text editor?

Why does a zip file appear larger than the source file especially when it is text?

Why is the size of a pointer to something on the heap larger than the size of a stack variable?

File allocation size issue: Size on disk larger than expected

My compressed file have larger file size than the original file

How do I ack-grep exclude file type *.sql files or file size larger than >3MB?

When using Photoshop to 'optimise' an image, why does it result in the image file actually becoming larger?

How to compress files larger than a certain size in a directory?

Make wget not download files larger than X size

Linux show files in directory larger than 1 GB and show size

Why are image sequences larger (in size) than the source videos?

Why is Java 6 compiled class size larger than Java 5?

Why is the resident set size (RSS) of my program larger than the executable?

why one number is larger than a identical number in Matlab?