6
votes

For the following code, I am getting the error I have put in title:

import scipy.io as sio
import numpy as np

temp = np.load('temp.npy')
sio.savemat('final.mat',temp)

Although AttributeError is a common error in python, I did not find anything useful for 'items' as mentioned in the title. How can we fix this?

2

2 Answers

13
votes

It takes a dict as the second argument not an array:

From the docs:

mdict : dict

Dictionary from which to save matfile variables.

I am not overly familiar but I imagine you pass the name as the key and the array as the value, something like:

sio.savemat('final.mat',{"foo":temp})
0
votes

I solved this issue as follow:

from scipy.io import savemat
import numpy as np
num= np.arange(20)
mymat={'num':num}
savemat('mymat.mat', mymat)