【发布时间】:2015-08-16 09:20:45
【问题描述】:
在使用元组列表(使用 python 2.7.8 和 numpy 1.9.1)索引平面 numpy 数组时,我注意到一些令人困惑的行为。我的猜测是,这与数组维度的最大数量(我相信是 32)有关,但我一直无法找到文档。
>>> a = np.arange(100)
>>> tuple_index = [(i,) for i in a]
>>> a[tuple_index] # This works (but maybe it shouldn't)
>>> a[tuple_index[:32]] # This works too
>>> a[tuple_index[:31]] # This breaks for 2 <= i < 32
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: too many indices for array
>>> a[tuple_index[:1]] # This also works...
如果元组列表是 32 个或更大的元素,它会被“扁平化”吗?这是否记录在某处?
【问题讨论】:
-
有趣的是,我收到一条不同的错误消息:
IndexError: unsupported iterator index。使用 python 2.7 和 numpy 1.8.2 -
抱歉,我应该指定版本(python 2.7.8;numpy 1.9.1)。我已经更新了问题。
标签: python arrays numpy indexing