0

I have a 3D float numpy array and wish to iterate over the 2D planes in it on a specific axis.

for 2D in 3D: iterates over the axis 0. So 2D will be 3D[0,:,:] 3D[1,:,:] etc. at each iteration. How can I specify the axis to get 3D[:,:,0] 3D[:,:,1] etc

Uğur Dinç
  • 303
  • 3
  • 16
  • 1
    You need to give a bit more context here. Are you talking about a numpy array perhaps? The Python standard library has no types that support tuple indexing, or axes. – Martijn Pieters Dec 29 '18 at 23:08
  • Sorry you are right of course. Numpy arrays, yes – Uğur Dinç Dec 29 '18 at 23:09
  • I just reviewed that other question before asking this one in fact I thought it was more about time efficiency. It might be my poor python knowledge, I couldn't really understand the syntax to do this there, and concluded maybe it is not there at all, since the question was about timing :( – Uğur Dinç Dec 29 '18 at 23:16
  • The question there is not about timing. That the accepted answer chose to focus on timing is only to explain why `.swapaxis()` is a good approach, and so is using a `range(array.shape[...])` loop. – Martijn Pieters Dec 29 '18 at 23:22

0 Answers0