访问字典中的项目(python)

时间:2017-09-01 18:10:19

标签: python dictionary

假设我有一个数据存储在python3的字典中,其中键为:data,id,index。所有数据都以data['data']的形式存储在字典中。以下是摘录

   {'data': array([[7008, 7008, 6080, ..., 4752, 4816, 4688],
               [5824, 5824, 5120, ..., 5264, 5184, 5040],
               [5584, 5584, 4752, ..., 5040, 4928, 4736],
               ..., 
               [4480, 4704, 4304, ..., 4000, 4016, 4096],
               [4624, 4768, 4416, ..., 4064, 3984, 4080],
               [4208, 4464, 4864, ..., 4048, 4112, 3984]], dtype=int64), 

    {'id': array([ 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 10, 10, 10, 10, 10,
           10, 10, 10, 10, 10,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  3,  3,
            3,  3,  3,  3,  3,  3,  3,  3,  4,  4,  4,  4,  4,  4,  4,  4,  4,8,
            8,  8,  8,  8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9],dtype=int64)}}

,同样data[index]dtype=object

我有8个独特的指数。

np.unique(data['index'])
array(['15', '16', 'A', 'A1', 'A2', 'B', 'C', 'D'], dtype=object)

现在我如何从索引中访问相关的data['data']?假设我想提取索引值15的数据。如何提取这个。?

data['index']

返回所有索引和

data['data'].data['index'][15] 

显然不是正确的做法。

感谢您的帮助。

0 个答案:

没有答案
相关问题