Multiple indices for numpy array: IndexError: failed to coerce slice entry of type numpy.ndarray to integer

Multiple indices for numpy array: IndexError: failed to coerce slice entry of type numpy.ndarray to integer

是否有如下所述的在 numpy 数组中进行多重索引的方法?

arr=np.array([55, 2, 3, 4, 5, 6, 7, 8, 9])
arr[np.arange(0,2):np.arange(5,7)]

output:
IndexError: too many indices for array

Desired output:
array([55,2,3,4,5],[2,3,4,5,6])

这个问题可能类似于计算数组的移动平均值(但我想在没有提供任何函数的情况下进行计算)。

这是一种使用 strides -

的方法
start_index = np.arange(0,2)
L = 5     # Interval length
n = arr.strides[0]
strided = np.lib.stride_tricks.as_strided
out = strided(arr[start_index[0]:],shape=(len(start_index),L),strides=(n,n))

样本运行-

In [976]: arr
Out[976]: array([55, 52, 13, 64, 25, 76, 47, 18, 69, 88])

In [977]: start_index
Out[977]: array([2, 3, 4])

In [978]: L = 5

In [979]: out
Out[979]: 
array([[13, 64, 25, 76, 47],
       [64, 25, 76, 47, 18],
       [25, 76, 47, 18, 69]])