For example, If I have Numpy arrays which is initialised by:
a = np.arange(12).reshape(6,2)
[out] array([[ 0, 1],
[ 2, 3],
[ 4, 5],
[ 6, 7],
[ 8, 9],
[10, 11]])
and
mask = np.array([0, 2])
My target is to mask array by range in a axis. like this
for i in mask:
target.append(a[i:i+3,:])
So, it should be:
[out] array([[[0, 1],
[2, 3],
[4, 5]],
[[4, 5],
[6, 7],
[8, 9]]])
but that's inefficient. Then, I've tried
a[mask:mask+3,:]
but it said
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: only integer scalar arrays can be converted to a scalar index