You can use numpy.apply_along_axis(). Assuming that your array is 2D, you can use it like:

import numpy as np

myarray = np.array([[11, 12, 13],
                    [21, 22, 23],
                    [31, 32, 33]])
def myfunction(x):
    return x[0] + x[1]**2 + x[2]**3

print(np.apply_along_axis(myfunction, axis=1, arr=myarray))
#[ 2352 12672 36992]
Answer from Saullo G. P. Castro on Stack Overflow
🌐
W3Schools
w3schools.com › python › numpy › numpy_array_iterating.asp
NumPy Array Iterating
Iterating means going through elements one by one. As we deal with multi-dimensional arrays in numpy, we can do this using basic for loop of python.
Discussions

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
How do I iterate over rows and columns? Can't find a tutorial on it.
2d array: For x in list: For y in otherlist: Just copied the 1st Google search url, there's probably hundreds: https://www.tutorialspoint.com/python_data_structure/python_2darray.htm More on reddit.com
🌐 r/learnpython
14
1
October 26, 2023
python - Iterate over a numpy Matrix rows - Stack Overflow
First, I tried to find an answer to my question ( which I think is pretty basic) searching in google and in the site, but nothing came up. I'm trying to get the rows from a numpy matrix, but I can... More on stackoverflow.com
🌐 stackoverflow.com
Why is iterating over rows in a dataframe considered bad practice, and what's an acceptable alternative to it?
Because pandas operations are usually vectorized, when we talk about vectorization, it means "accept NumPy arrays and return another array or value" in pandas speak, because it uses numpy under the hood. Now the question becomes, why should we use numpy vectorization? For one, numpy calls C code and Fortran code that is hightly optimized for math/linear algebra. It allows us to bypass in some form, the slowness of an interpreted language like Python. You can read about it here . When you loop over arrays, dataframes, etc you actually call regular Python code which is very slow in comparison. But pandas has documentation on iteration when you unfortunately have no choice but to do it, typically when present input depends on past transformations in the loop. There are still multiple warnings that you should look for a vectorized implementation, so if possible you should try to vectorize the different steps of your function instead of looping. More on reddit.com
🌐 r/learnpython
16
7
April 23, 2020
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-iterating-over-array
Numpy - Iterating Over Arrays - GeeksforGeeks
July 23, 2025 - It allows iteration in different orders and provides better control over the iteration process. Python · import numpy as np # Using nditer arr = np.array([[1, 2], [3, 4]]) for element in np.nditer(arr): print(element) Output · 1 2 3 4 · We can also specify the order of iteration (row-major order 'C' or column-major order 'F'): Python ·
🌐
TutorialsPoint
tutorialspoint.com › numpy › numpy_iterating_over_array.htm
NumPy - Iterating Over Array
Iteration order in NumPy refers to the sequence in which elements of an array are accessed during iteration. By default, NumPy arrays are iterated over in a row-major order, also known as C-style order.
🌐
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?

🌐
NumPy
numpy.org › doc › stable › reference › arrays.nditer.html
Iterating over arrays — NumPy v2.5 Manual
The nditer object provides an order parameter to control this aspect of iteration. The default, having the behavior described above, is order=’K’ to keep the existing order. This can be overridden with order=’C’ for C order and order=’F’ for Fortran order.
🌐
IncludeHelp
includehelp.com › python › iterating-over-numpy-matrix-rows-to-apply-a-function-each.aspx
Python - Iterating over NumPy matrix rows to apply a function each?
December 28, 2023 - # Import numpy import numpy as np # Creating a numpy array arr = np.array([[10, 11, 12],[1, 2, 3],[4, 5, 6]]) # Display original array print("Original array:\n",arr,"\n") # defining a function def fun(x): return x[2]**2+100 # Applying function to each row res = np.apply_along_axis(fun, axis=1, arr=arr) # Display result print("Result:\n",res) In this example, we have used the following Python basic topics that you should learn: ... NumPy vstack vs.
Find elsewhere
🌐
Pluralsight
pluralsight.com › blog › tech guides & tutorials
Iterating Numpy Arrays | Pluralsight
November 12, 2018 - To iterate each cell in the two-dimensional array, nest the for loop. for row in A: for cell in row: print(cell, end=' ') ... If you do not want to write two for loops, you can use the flatten function that flattens the two-dimensional array ...
🌐
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 - Now to Iterate over a row: for e in data[3,:]: print(e) returns · 9 8 9 1 4 2 2 3 · Iterating Numpy Arrays · Iterating Arrays · Author · Earth observation scientist and developer, I explore satellite data, fire detection, and environmental analytics using Python and machine learning.
🌐
NumPy
numpy.org › devdocs › reference › arrays.nditer.html
Iterating over arrays — NumPy v2.6.dev0 Manual
The nditer object provides an order parameter to control this aspect of iteration. The default, having the behavior described above, is order=’K’ to keep the existing order. This can be overridden with order=’C’ for C order and order=’F’ for Fortran order.
🌐
Kaggle
kaggle.com › general › 521858
Numpy Arrays Iterating | Kaggle
The nditer() function simplifies iteration over NumPy arrays of any dimension, allowing us to access each element in a single loop.
🌐
Reddit
reddit.com › r/learnpython › how do i iterate over rows and columns? can't find a tutorial on it.
r/learnpython on Reddit: How do I iterate over rows and columns? Can't find a tutorial on it.
October 26, 2023 -

The problem I want to solve is this- I want to find a certain item in a list that is formatted like a chart, something like this:

list=[1,2,3,4,5
      2,4,6,8,10
      3,6,9,12,16
      4,8,12,16,20
      5,10,15,20,25]

So I want to be able to call values within this makeshift chart. For instance, if I wanted to call a certain value within this list like--- Row 2, column 3.... this would return 6.

I think this can be done with iterations???? I saw a video of it somewhere but I can't find anything on google about this, I think I just don't know how to explain it. How do I do what I want to do in python 3+, without using panda?

Would really appreciate some code, but if you can just tell me what I should look up to learn how to do this, it would help just as much! Thanks!!!!

🌐
Medium
medium.com › @programminghunk › iterating-over-numpy-arrays-4620af1ae987
Iterating over Numpy arrays. The most popular and well-known way… | by Pushpendra Tyagi | Medium
May 29, 2020 - The most popular and well-known way iterate over a ndarray is a basic iteration loop available in Python. For example, import numpy as np # Accessing using for loop #1-D array lang = np.array(['Java','Python','C++','C#','C','JavaScript']); for item in lang: print(item) #2-D array nums = np.array([[10, 20, 30],[40, 50, 60],[70, 80, 90]]) for row in nums: for item in row: print(item) #3-D array nums3d = np.array([[[10, 20, 30],[40, 50, 60]],[[70, 80, 90],[100, 110, 120]]]) for row in nums3d: for col in row: for item in col: print(item) NumPy package also provides an iterator object numpy.nditer().
🌐
Scaler
scaler.com › home › topics › numpy › numpy iterating over array
NumPy Iterating Over Array - Scaler Topics - Scaler Topics
September 9, 2022 - However, we have to perform multiple loops to iterate over a multidimensional array. To avoid using multiple loops, we use a NumPy function called nditer. The nditer function is used for iterating each array element in a single iteration. Let's look at the following examples where an array ...
🌐
Python Like You Mean It
pythonlikeyoumeanit.com › Module3_IntroducingNumpy › ArrayTraversal.html
Iterating Over Arrays & Array-Traversal Order — Python Like You Mean It
The row-major array traversal methodology, which is utilized by NumPy by default. NumPy provides valuable tools for iterating over any array, such that each element can be visited in the array, regardless of the array’s shape.
🌐
YouTube
youtube.com › watch
Iterating Through Numpy Arrays - Numpy For Machine Learning 6 - YouTube
In this video we'll learn how to iterate thru Numpy Arrays using basic Python For Loops as well as the nditer() function that comes with Numpy.Iterating over...
Published: July 5, 2022
🌐
NumPy
numpy.org › doc › 2.1 › reference › arrays.nditer.html
Iterating over arrays — NumPy v2.1 Manual
The nditer object provides an order parameter to control this aspect of iteration. The default, having the behavior described above, is order=’K’ to keep the existing order. This can be overridden with order=’C’ for C order and order=’F’ for Fortran order.
🌐
Analytics Vidhya
analyticsvidhya.com › home › iteration in python – enumerate(), item(), np.nditer(), iterrows()
Iteration in Python | enumerate(), item(), np.nditer(), iterrows()
October 22, 2024 - If we’re dealing with a 2D Numpy array, it’s more complicated. A 2D array is built up of multiple 1D arrays. To explicitly iterate over all separate elements of a multi-dimensional array, we’ll need this syntax: