I have a 3D array like A
A = np.random.randint(20,size=(4,2,2))
array([[[18, 8],
[ 2, 11]],
[[ 9, 8],
[ 9, 10]],
[[ 0, 1],
[10, 6]],
[[ 1, 8],
[ 4, 2]]])
What I want to do is to apply a function to some indices along the axis=0. For example, I want to multiply the A[1] and A[3] by 2 and add 10 to them. I know one option is this:
for index in [1,3]:
A[index] = A[index]*2+10
Which gives:
array([[[18, 8],
[ 2, 11]],
[[28, 26],
[28, 30]],
[[ 0, 1],
[10, 6]],
[[12, 26],
[18, 14]]])
But my original array is of the size of (2500, 300, 300) and I need to apply the function to 500 non-consecutive indices along the axis=0 every time. Is there a faster and more pythonic way to do it?