'map' 对象不可订阅,如何提取部分地图
'map' object is not subscriptable,How to extract a part of map
66 test_indexes = set(random.sample(indexes, len(indexes)//2)) # removing 50% edges from test data
67 train_indexes = set(indexes).difference(test_indexes)
---> 68 test_list = [edge_list[i] for i in test_indexes]
69 train_list = [edge_list[i] for i in train_indexes]
70 return train_list,test_list
TypeError: 'map' 对象不可订阅
我想知道如何将边缘列表(这是一张地图)的一部分放入test_list>请帮我解决这个问题
所以我相信根据这些信息,在某些时候您可能已经尝试通过使用 map 将函数映射到另一个列表来创建列表 (edge_list)。请以下面为例
lst = [1,2,3]
new_lst = map(lambda x: x**2, lst)
type(new_lst)
这个 returns 一个 'map' 不可迭代的对象。尝试将此示例中的 new_lst 和您的 edge_list 强制转换为列表:
lst = [1,2,3]
new_lst = list(map(lambda x: x**2, lst))
type(new_lst)
66 test_indexes = set(random.sample(indexes, len(indexes)//2)) # removing 50% edges from test data
67 train_indexes = set(indexes).difference(test_indexes)
---> 68 test_list = [edge_list[i] for i in test_indexes]
69 train_list = [edge_list[i] for i in train_indexes]
70 return train_list,test_list
TypeError: 'map' 对象不可订阅
我想知道如何将边缘列表(这是一张地图)的一部分放入test_list>请帮我解决这个问题
所以我相信根据这些信息,在某些时候您可能已经尝试通过使用 map 将函数映射到另一个列表来创建列表 (edge_list)。请以下面为例
lst = [1,2,3]
new_lst = map(lambda x: x**2, lst)
type(new_lst)
这个 returns 一个 'map' 不可迭代的对象。尝试将此示例中的 new_lst 和您的 edge_list 强制转换为列表:
lst = [1,2,3]
new_lst = list(map(lambda x: x**2, lst))
type(new_lst)