当我使用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。 - swenzel