欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

numpy array TypeError: only integer scalar arrays can be converted to a scalar index

程序员文章站 2024-03-02 21:27:58
...

This appears to be an issue with the latest version of Numpy. A recent change made it an error to treat a single-element array as a scalar for the purposes of indexing.

*上有相关的讨论
https://*.com/questions/42128830/typeerror-only-integer-scalar-arrays-can-be-converted-to-a-scalar-index

我的方法是在数组后加上.flatten()

举例:

#原代码
print("The ball picked:", ", ".join(map(lambda x: observations[x], seen)))
#更改后
print("The ball picked:", ", ".join(map(lambda x: observations[x], seen.flatten())))