How to Iterate On Each Scalar Element of 3-D Array in Python


In this example, we will learn how to iterate on each scalar element of the 3-D array in Python.

Source Code

import numpy as np

n = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])

for x in n:
    for y in x:
        for z in y:
            print(z)

Output:

1
2
3
4
5
6
7
8
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments