NumPy TutorialLesson 11Free preview
NumPy Array Iterating
This lesson is part of NumPy · All levels
Summary
NumPy array iteration can be performed with regular for iterations for a one-dimensional array, whereas a multidimensional array requires a np.nditer function to make each element affordable. To get the index and value pairs, np.ndenumerate is available. Both of these functions facilitate the processing of elements that have a layered structure.
Key points
- For x in arr works directly on the 1D array.
- It goes through all the elements of the multidimensional array.
- Np.ndenumerate produces a pair (index, value).
- 'external_loop' makes the iteration yields pieces per line.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.