[SciPy-dev] matlab.io squeezes by default

Nathan Bell wnbell@gmail....
Tue Feb 12 19:59:33 CST 2008

I noticed that scipy.io.loadmat() had squeeze_me=True set by default.
Was there a compelling reason for this default choice?  I would think
that most people expect (1,N) matrices and (N,1) matrices to retain
their shapes when loaded.  Here's a simple example that illustrates
the problem.

from scipy.testing import *
from scipy import array, matrix
from scipy.io import savemat, loadmat

A = matrix([[1,2,3]])
B = matrix([[1],[2],[3]])

X = {'A' : A, 'B' : B }

savemat('temp.mat', X )

#Y = loadmat('temp.mat', squeeze_me=False)  # preserves shape
Y = loadmat('temp.mat')  #does not preserve shape

assert_equal( Y['A'], A)
assert_equal( Y['B'], B)

For now, I have changed the default to squeeze_me=False.

Nathan Bell wnbell@gmail.com

More information about the Scipy-dev mailing list