python - 列表(地图)错误: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
正确。只是不确定如何显示地图结果。
解决方案
seen
是一个列表的列表,它的元素是一个列表,你正试图将它用作列表的索引。删除定义中的外部方括号seen
,或映射其串联。
推荐阅读
- google-smart-home - chrome 开发工具检查设备连接到哪个端口以进行本地实现?
- prometheus - 如何计算不同计数器的总和
- powershell - 比较powershell中的2个哈希表和不同时的输出
- mongodb - MongoDB 没有使用正确的索引
- d3.js - d3.scaleTime 仅呈现 NaN
- javascript - 将 Passport.js 与 pub/private 键一起使用时出现未经授权的响应
- r - 使用 npplregbw(部分线性半参数回归)选择带宽时出现错误
- javascript - 如何设置只读选项以显示禁用?
- macos - 如何强制解压缩列表使用 unicode UTF-8
- google-classroom - Google Classroom API Python 列表课程作业