Python Forum

Full Version: 3D array manipulation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear all,

So for a homework assignment, I have trouble manipulating a 3D array (26,26,500). From the 300th element in the last row, all values should be turned into zeros. How should I go about this? I've tried working with for loops, but its not going well. I've included a snippet of the code. data_dir is the 3D array.

I=300
for i in range(500-I):
    data_dir[:,:,(500-i):]=0
Please use proper coding tags while posting your thread. Also, please show the full code to us
See BBCode to know more about coding tags
Simplify
for i in range(300,501):
    data_dir[:,:,i]=0
If this about using NumPy, you can just assign to the entire subarray, e.g.

data_dir[..., 300:] = 0