Python Forum
3D array manipulation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3D array manipulation
#1
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
Reply
#2
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
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#3
Simplify
for i in range(300,501):
    data_dir[:,:,i]=0
Reply
#4
If this about using NumPy, you can just assign to the entire subarray, e.g.

data_dir[..., 300:] = 0
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020