【发布时间】:2018-09-04 04:14:36
【问题描述】:
我想多次切出数组foo 的一部分。目前我正在使用一个 for 循环,我想通过矩阵计算来代替它以获得更好的速度性能。
foo = np.arange(6000).reshape(6,10,10,10)
target = np.zeros((100,6,3,4,5))
startIndices = np.random.randint(5, size=(100))
这是我目前的方法。
for i in range(len(target)):
startIdx=startIndices[i]
target[i, :]=foo[:, startIdx:startIdx+3,
startIdx:startIdx+4,
startIdx:startIdx+5]
我尝试将切片表示为数组,但找不到合适的表示。
【问题讨论】:
标签: arrays python-2.7 performance numpy slice