Python - Filter dictionary with multiple keys -


my dictionary "mat_contents" looks this:

{'__globals__': [], '__header__': b'matlab 5.0 mat-file, platform: pcwin64, created on: wed jul 05 14:02:28 2017', '__version__': '1.0', 'traindata': array([[  3.37988024e-01,   2.87425150e-01,   3.36669403e-01, ...,        3.47222222e+00,   2.89078631e+01,   2.66129299e+02],     [  3.78449348e-01,   3.68259383e-01,   3.77523300e-01, ...,        7.93650794e+00,   7.49814148e+01,   3.39940867e+02],     [  4.20835393e-01,   3.83079983e-01,   4.20191384e-01, ...,        4.13223140e+00,   3.17110530e+01,   3.13224462e+02],     ...,      [  8.27125382e-01,   8.31804281e-01,   8.29763490e-01, ...,        2.05761317e+00,   1.37089318e+01,   2.36950648e+02],     [  6.25915416e-01,   7.65430139e-01,   6.26844490e-01, ...,        4.38596491e+00,   2.86553873e+01,   4.07901114e+02],     [  4.66673740e-01,   4.73032714e-01,   4.66367545e-01, ...,        9.61538462e+00,   2.73538135e+01,   2.90957268e+02]]), 'trainlabels': array([[array(['2'],     dtype='<u1')],     [array(['3'],     dtype='<u1')],     [array(['2'],     dtype='<u1')],     ...,      [array(['2'],     dtype='<u1')],     [array(['2'],     dtype='<u1')],     [array(['2'],     dtype='<u1')]], dtype=object)} 

i want filter (subset) given number of rows (containing 'traindata' , 'trainlabels') according value of trainlabels. far (with help) got following command:

labels = [mat_contents['trainlabels'][0][i] i, val in enumerate(mat_contents['traindata'].flatten()[0]) if val == 1]  result = np.random.choice(labels, 2, replace=false) 

however, following error:

 typeerror: 'numpy.float64' object not iterable 

i tried solve in previous question: python - subtract number of samples given in dictionary structure

i'm stuck , not know how solve it.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -