NumPy 数组可以与其他数组一起索引。为了显示:
>>> import numpy as np
>>> arr = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0et ], 'f4')
>>> ids = np.array([0, 2], 'i4')
arr[ids]
array([ 0., 2.], dtype=float32)
但是,如果我想要一个包含索引指向的值加上三个后续元素的多数组该怎么办?
>>> arr[ids:(ids+4)]
Traceback (most recent call last):
File "<console>", line 1, in <module>
IndexError: invalid slice
预期的:
array([[0. 1. 2. 3.], [2. 3. 4. 5.]], dtype=float32)
如何使这成为可能?