-1

I want to save a list of NumPy array as a mat file but raised with error 'list' object has no attribute 'items'. You can see my try below:

import numpy as np
import scipy.io

output=[]
for i in range(10):
  a=np.random.randint(0,100,size=(60,60,4))
  output.append(a)
scipy.io.savemat('test.mat', output)
Saman
  • 49
  • 4
  • 4
    Doesn’t [`savemat()`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.savemat.html) at expect a dictionary as its second argument? – Mark Nov 23 '21 at 03:55
  • 1
    in future, please also provide full error trace. in this case, we arrive at the conclusion because we (correctly) guess that `savemat` is raising the error, however a stack trace would make this more clear. – rv.kvetch Nov 23 '21 at 03:57

1 Answers1

1

Here is the answer:

import numpy as np
import scipy.io

output=[]
for i in range(10):
  a=np.random.randint(0,100,size=(60,60,4))
  output.append(a)
scipy.io.savemat('test.mat',  mdict={'my_list': output})
Saman
  • 49
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 23 '21 at 04:27