Issue
I was trying to follow the example of "https://github.com/EBjerrum/Deep-Chemometrics/blob/master/Deep_Chemometrics_with_data_augmentation.py.ipynb", but when executing the first part of the code I immediately get the error.
#code
import scipy.io as sio
import numpy as np
def get_xY(filename, maxx=600):
#sio.whosmat(filename)
matcontents = sio.loadmat(filename)
keys = matcontents.keys()
for key in list(keys):
if key[0] == '_':
keys.remove(key)
keys.sort()
d = {}
for key in keys:
data = matcontents[key][0][0]
if key[-1] == "Y":
Ydata = data[5]
d[key] = Ydata
else:
xdata = data[5][:,:maxx]
d[key] = xdata
d["axisscale"]= data[7][1][0][0][:maxx].astype(np.float)
return d
filename = 'Dataset/nir_shootout_2002.mat'
dataset = get_xY(filename)
' AttributeError: 'dict_keys' object has no attribute 'remove' '
Solution
It seems like changing keys.remove(key)
to del keys[key]
worked for them. (From a comment)
You are getting this problem when you load the matlab file and the code expecting a dict where it doesn't find a dict.
The specific error is 'dict_keys' object has no attribute 'remove'
. That's how I know that python isn't finding a dict.
Your code:
matcontents = sio.loadmat(filename)
keys = matcontents.keys()
Change that to:
matcontents = sio.loadmat(filename)
print('matcontents',type(matcontents),matcontents)
keys = matcontents.keys()
print('keys',type(keys),keys)
To make sure that the data is loaded as you expect.
This page also mentions that newer versions of matlab files (7.3) must be imported differently. Read .mat files in Python
Answered By - shanecandoit
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.