AttributeError: object 'numpy.ndarray' has no attributes 'items'

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

import scipy.io as sio
import numpy as np

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

      

Although AttributeError

a common mistake in python, I haven't found anything useful for 'items'

, as mentioned in the title. How can we fix this?

+3


source to share


1 answer


It takes a dict as its second argument, not an array:

From the docs :

mdict: dict



A dictionary from which matfile variables can be saved.

I'm not too used to it, but I imagine you are passing a name as a key and an array as a value, for example:

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

      

+6


source







All Articles