我有一个大的一维整数数组,我需要取下切片.这是微不足道的,我只是这样做a[start:end].问题是我需要更多这些切片.a[start:end]如果start和end是数组,则不起作用.For循环可以用于此,但我需要它尽可能快(这是一个瓶颈),所以欢迎本地numpy解决方案.
为了进一步说明,我有这个:
a = numpy.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], numpy.int16)
start = numpy.array([1, 5, 7], numpy.int16)
end = numpy.array([2, 10, 9], numpy.int16)
Run Code Online (Sandbox Code Playgroud)
并需要以某种方式使它成为这个:
[[1], [5, 6, 7, 8, 9], [7, 8]]
Run Code Online (Sandbox Code Playgroud)