首页 > 解决方案 > 列表(地图)错误:TypeError:只能将整数标量数组转换为标量索引

问题描述

我在 Anaconda 中使用 Python 3.6.3。我正在尝试:

observations = ["red", "white"] 
seen = np.array([[0,1,0]]).T
list(map(lambda x: observations[x], seen))

然后发生了这个错误:

TypeError:只有整数标量数组可以转换为标量索引

我查了地图:

map(lambda x: observations[x], seen)
map at 0x2ab8c869e80>

所以我认为我使用map正确。只是不确定如何显示地图结果。

标签: pythonnumpy

解决方案


seen是一个列表的列表,它的元素是一个列表,你正试图将它用作列表的索引。删除定义中的外部方括号seen,或映射其串联。


推荐阅读