list indices must be integers or slices, not numpy.float64
时间: 2023-10-12 19:04:16 浏览: 131
浅谈pytorch中torch.max和F.softmax函数的维度解释
5星 · 资源好评率100%
在Python中,列表的索引必须是整数或者切片,不能是浮点数类型,包括numpy.float64类型。当我们使用浮点数作为列表的索引时,会出现报错"list indices must be integers or slices, not float"。例如,如果我们有一个列表l=[1,2,3,4,我们不能使用l来访问列表中的元素。
同样,当我们使用numpy数组中的浮点数作为索引时,也会出现相同的报错。例如,我们有两个二维数组b和c,并尝试计算它们的差的绝对值之和,即B=[np.sum(np.abs(a - c)) for a in b。当我们运行此代码时,会出现报错"TypeError: list indices must be integers or slices, not tuple",提示列表索引必须是整数或者切片,而不是元组。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [numpy.float64不能当作列表索引](https://blog.csdn.net/zy1620454507/article/details/127444586)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* [python报错 list indices must be integers or slices, not tuple](https://blog.csdn.net/Electrical_IT/article/details/114916652)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文