How to Iterate On Each Scalar Element of NumPy Array


In this example we will show how to iterate on each scalar element of the NumPy array using the nditer() function in Python.

Source Code

import numpy as np

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

for i in np.nditer(n):
    print(i)

Output:

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