2016-11-30 46 views
0

祝大家明天冬天一切顺利。尽管如此,为了我的日子变好,我需要让我的嵌套字典正确...切出嵌套字典值中的第N个元素

DATA。 (字典中键是元组,值是二维numpy阵列)

lst = [(0), (1), (1,2), (1,2,3), (1,2,3,4)] 
array = np.random.random((5,2)) 
dictionary = dict(zip(lst, array)) 

问题。如何删除字典值中的第一个元素(数组的第一个维度)?或者我如何切片字典,以便只有值中的第二个元素仍然存在(数组的第二维)?

回答

1

如果我理解正确,这可能做你的工作:

lst = [(0), (1), (1,2), (1,2,3), (1,2,3,4)] 
array = np.random.random((5,2)) 
dictionary = dict(zip(lst, array)) 
element = 0 
dictionary = dict(zip(dictionary.keys(), map(lambda x: np.delete(x, element), dictionary.values())))