Try np.ndenumerate:

>>> a =numpy.array([[1,2],[3,4]])
>>> for (i,j), value in np.ndenumerate(a):
...  print(i, j, value)
... 
0 0 1
0 1 2 
1 0 3
1 1 4
Answer from Lifu Huang on Stack Overflow
🌐
W3Schools
w3schools.com › python › numpy › numpy_array_iterating.asp
NumPy Array Iterating
import numpy as np arr = np.array([1, 2, 3]) for x in np.nditer(arr, flags=['buffered'], op_dtypes=['S']): print(x) Try it Yourself » · We can use filtering and followed by iteration.
Spaces
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
Practice
Practice coding problems on W3Schools. Write code, submit, and get instant feedback.
W3Schools app iOS & Android NEW
The W3Schools app turns coding fundamentals into a game. Bite-sized lessons, streaks and XP. Free on iOS and Android.
Python For Loops
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-iterating-over-array
Numpy - Iterating Over Arrays - GeeksforGeeks
July 23, 2025 - To iterate over individual elements of a 2D array, the array can be flattened using the .flat attribute. ... import numpy as np arr_2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) for element in arr_2d.flat: print(element)
Discussions

Looping through each item in a numpy array? - Stack Overflow
Try it and see! However, iterating through a 2D array completely defeats the point of using numpy, i.e. efficient array operations. Read this doc page, for instance. ... Note that your current syntax is not correct, even for iterating through nested lists. You should rather be using for row ... More on stackoverflow.com
🌐 stackoverflow.com
python - How can I loop through 2D NumPy array using x and y coordinates without getting out of bounds error? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Turn scattered docs and code into trusted AI context. Explore the new Stack Internal platform More on stackoverflow.com
🌐 stackoverflow.com
loops - Iterating over a 2 dimensional python list - Stack Overflow
I have created a 2 dimension array like: rows =3 columns= 2 mylist = [[0 for x in range(columns)] for x in range(rows)] for i in range(rows): for j in range(columns): mylist[i][j] = '% More on stackoverflow.com
🌐 stackoverflow.com
Iterating through a numpy array
A quick note to start: In numpy, the row index comes before the column index, so, for example, a 3x2 array would have the form [[1,2],[3,4],[5,6]]. In any case, for an nx2 array called arr you can iterate through the pairs (rows) as you would through elements of a regular sequence: for n in arr: n # is your pair For a 2xn array, you can use for i in xrange(arr.shape[1]): arr[:, i] # is your pair but there are a number of ways to do this second form. Here 's a stackoverflow entry that treats this question in more detail. Worth mentioning: In general, if you can avoid iterating over a numpy array, you should. The iteration sacrifices some of the performance improvements over regular python given by the C-implemented numpy arrays. Numpy (and scipy) have a large selection of functions that allow you to avoid iteration (especially by leveraging the axis keyword to perform some computation over a specific axis) -- so search through the docs a bit before committing to this route. (an example of what I mean: to obtain the mean value of each of your tuples, use np.mean(arr, axis=1) in the nx2 case or axis=0 in the 2xn case to get an n-lengthed sequence of the mean of each pair; there are many functions like this) More on reddit.com
🌐 r/learnpython
7
2
November 14, 2014
🌐
Python Guides
pythonguides.com › iterate-through-a-2d-array-in-python
How To Iterate Through A 2D Array In Python?
July 16, 2026 - Looping over a NumPy array with a plain for loop gives you whole rows. np.nditer() is a NumPy function built specifically to iterate through every single element, across all dimensions, in one pass. For a deeper look at building and shaping these structures, see this guide on Python NumPy 2D arrays and this overview of the Python NumPy array basics.
🌐
Studyopedia
studyopedia.com › home › how to iterate numpy arrays
How to Iterate Numpy Arrays - Studyopedia
March 29, 2026 - import numpy as np # Create a Numpy 2D array n = np.array([[5, 10], [15, 20], [25, 30]]) print("Two-Dimensional Array = \n", n) print("Type = ", type(n)) print("DataType = ", n.dtype) print("\nIterating...") for a in n: print(a)
🌐
Finxter
blog.finxter.com › home › learn python blog › how to iterate over a numpy array
How to Iterate over a NumPy Array - Be on the Right Side of Change
August 16, 2022 - This method uses a for loop and Python’s built-in itertools library to iterate through a NumPy array.
🌐
Medium
medium.com › @souvikdutta.aec › how-to-iterate-on-a-numpy-array-6c4cb1827846
How To Iterate on a Numpy Array | Medium
January 26, 2023 - Iterating in Numpy array means is going through the elements of the array elements one by one. If we want to iterate over a Multi Dimensional Array In Python then we can simply do this by using the for loop in Python.
Find elsewhere
🌐
NumPy
numpy.org › doc › stable › reference › arrays.nditer.html
Iterating over arrays — NumPy v2.5 Manual
The most basic task that can be done with the nditer is to visit every element of an array. Each element is provided one by one using the standard Python iterator interface.
🌐
Pluralsight
pluralsight.com › blog › tech guides & tutorials
Iterating Numpy Arrays | Pluralsight
November 12, 2018 - NumPy provides a multi-dimensional iterator object called nditer to iterate the elements of an array.
🌐
Kaggle
kaggle.com › general › 521858
Numpy Arrays Iterating | Kaggle
To iterate through a 2D array with a step size, We can use slicing within nditer().
🌐
Moonbooks
en.moonbooks.org › Articles › How-to-iterate-over-a-row-in-a-numpy-array-or-2D-matrix-in-python-
How to iterate over a row in a numpy array (or 2D matrix) in python ?
April 12, 2021 - How to iterate over a row in a ... with index 3: data[3,:] returns here · array([9, 8, 9, 1, 4, 2, 2, 3]) Now to Iterate over a row: for e in data[3,:]: print(e) returns ·...
🌐
i2tutorials
i2tutorials.com › home › numpy tutorial › numpy – iterating over array
NumPy - Iterating Over Array | i2tutorials
April 29, 2019 - In this tutorial, we will learn about array iteration in Numpy. In python, we have used iteration through lists.
🌐
Stack Overflow
stackoverflow.com › questions › 16548668 › iterating-over-a-2-dimensional-python-list
loops - Iterating over a 2 dimensional python list - Stack Overflow
I have created a 2 dimension array like: rows =3 columns= 2 mylist = [[0 for x in range(columns)] for x in range(rows)] for i in range(rows): for j in range(columns): mylist[i][j] = '%...
🌐
Reddit
reddit.com › r/learnpython › iterating through a numpy array
r/learnpython on Reddit: Iterating through a numpy array
November 14, 2014 -

I know this is a dumb question, but I've scoured Google for the documentation, Stack Overflow, etc. but I can't figure out how to do this. I'm really used to C so I might be approaching this wrong.

Basically, I have a multidimensional array; specifically, it's n x 2. Another way of looking at it is that it's an array of tuples.

So suppose there are the points (1, 9), (2, 8), and (3, 7).

Now, my assumption is that [[1, 2, 3], [9, 8, 7]] is an nx2 array, and that [[1,9], [2, 8], [3, 7]] is a 2xn array, correct?

So my question is, in each case (given an nx2 and a 2xn array), how would I iterate through each ordered pair?

🌐
TutorialsPoint
tutorialspoint.com › numpy › numpy_iterating_over_array.htm
NumPy - Iterating Over Array
In NumPy, arrays are indexed starting from 0 for each dimension. Iterating with indices involves using nested loops to traverse through each dimension of the array and access elements using their specific indices.
🌐
Python Like You Mean It
pythonlikeyoumeanit.com › Module3_IntroducingNumpy › ArrayTraversal.html
Iterating Over Arrays & Array-Traversal Order — Python Like You Mean It
NumPy utilizes row-major ordering, as a default, for any operation that requires an array to be traversed. These two orderings are simple enough to follow for a 2D-array, but how do they manifest in arrays with higher dimensions, where we have to worry not only about rows and columns, but potentially “stacks of sheets with rows and columns” (which would be a 4D array) and so on?
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-iterate-over-columns-in-numpy
Python - Iterate over Columns in NumPy - GeeksforGeeks
February 26, 2023 - Now we used a for loop which would iterate x times (where x is the number of columns in the array) for which we used range() with the argument ary.shape[1] (where shape[1] = number of columns in a 2D symmetric array). In each iteration we output a column out of the array using ary[:, col] which means that give all elements of the column number = col. METHOD 2: In this method we would transpose the array to treat each column element as a row element (which in turn is equivalent of column iteration). ... # libraries import numpy as np # Creating an 2D array of 25 elements ary = np.array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) # This loop will iterate through each row of the transposed # array (equivalent of iterating through each column) for col in ary.T: print(col)
🌐
MindStick
mindstick.com › interview › 34411 › how-to-iterating-numpy-array
How to Iterating NumPy Array? – MindStick
November 12, 2025 - Iterating over a NumPy array means accessing its elements (one by one, or by row/column) using loops or built-in functions · If you have a 1-dimensional NumPy array, you can simply loop through it like a Python list:
🌐
Moonbooks
en.moonbooks.org › Articles › How-to-iterate-over-a-column-in-a-numpy-array-or-2D-matrix-in-python-
How to iterate over a column in a numpy array (or 2D matrix) in python ?
April 12, 2021 - How to iterate over a column in a numpy array (or 2D matrix) in python ? Note: in python column indices start at 0 (Zero-based numbering). To select an entire column, for instance column associated with index 4: data[:,4] returns here · array([6, 4, 8, 4, 9, 7, 0, 4, 6, 9]) Now to Iterate over a column: for e in data[:,4]: print(e) returns · 6 4 8 4 9 7 0 4 6 9 · Python – Iterate over Columns in NumPy · How to iterate through columns of a NumPy array in Python ·