TypeError: 'KeysView' object does not support indexing

Viewed 6675

I'm getting this error trying to analyze data from an HDF5 file directly in python. This code works fine on my linux machine, but I get this error trying to compile the same script on my mac in Spyder3. The reason I'm trying to use my mac is because I'm not sure how to write and run a script on linux terminal.

def dataProcessing(datafile):
import h5py
import numpy as np
import matplotlib.pyplot as plt
import pylab

f = h5py.File(datafile, 'r')
#print(f)
#print("Keys: %s" % f.keys())
groupKeyVal = f.keys()[4]
rawData = list(f[groupKeyVal])

rawDataMat = np.matrix(rawData)

for i in range(0,len(rawDataMat[:,0])):
    fig = rawDataMat[i,:]
    wav = np.squeeze(np.asarray(fig))
    plt.plot(wav)
    plt.show()
1 Answers
Related