Home > Mobile >  Changing the value of values after a particular index along one axis in a 3D numpy array
Changing the value of values after a particular index along one axis in a 3D numpy array

Time:11-28

I have a 3d array of format given below. The below is the one sample of the 3D array, like it , it contain more than 1000. sample

shape of the 3D array is (1000 x 10 x 5) The image contain one element (10 x 5) I want to change the value to 0 after the 3rd one on the last value check the figure below desired

I want to change like it for all the 1000 elements in my array. Is there a better way to do it other than using "for loop" ?

CodePudding user response:

import numpy as np

# Your array here:
arr = np.arange(50000).reshape(1000, 10, 5)

# Solution:
arr[:, 3:, -1] = 0
  • Related