[SciPy-user] savemat not working in SciPy 0.4.6?

Travis Oliphant oliphant at ee.byu.edu
Wed Feb 22 16:02:39 CST 2006

Albert Strasheim wrote:

>Hello all
>I'm trying to use the savemat function in SciPy 0.4.6.
>The following code doesn't work:
>from numpy import array
>from scipy.io import savemat
>savemat('foo.mat', {'x' : array([0])})
>The traceback:
>Traceback (most recent call last):
>  File "frags.py", line 3, in ?
>    savemat('foo.mat', {'x' : array([0])})
>  File "C:\Python24\Lib\site-packages\scipy\io\mio.py", line 875, in savemat
>    fid.fwrite(variable+'\x00','char')
>  File "C:\Python24\Lib\site-packages\scipy\io\mio.py", line 223, in write
>    numpyio.fwrite(self,count,data,mtype,bs)
>numpyio.error: Does not support extended types.
>Is anybody else experiencing this problem?
This was a bug.  This is updated in SVN.  Here's a work-around.


        data = asarray(data)

the write method of fopen class with

        if isinstance(data, str):
            N, buf = len(data), buffer(data)
            data = ndarray(shape=(N,),dtype='B',buffer=buf)
            data = asarray(data)

This is near line 218 of scipy/io/mio.py


More information about the SciPy-user mailing list