l = [[98, 25, 33,  9, 41],
[67, 32, 67, 27, 85],
[38, 79, 52, 40, 58],
[84, 76, 44,  9,  2]]

def fnd(l,value):
    for i,v in enumerate(l):
        if value in v:
            return {'row':i+1,'col':v.index(value)+1}
    return {'row':-1,'col':-1}
print(fnd(l,40))
{'row': 3, 'col': 4}
Answer from Kuldeep Singh Sidhu on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-using-2d-arrays-lists-the-right-way
Using 2D arrays/lists in Python - GeeksforGeeks
If we assign the 0th index to another integer say 1, then a new integer object is created with the value of 1 and then the 0th index now points to this new int object as shown below · Similarly, when we create a 2d array as "arr = [[0]*cols]*rows" ...
Published   December 20, 2025
🌐
Snakify
snakify.org › two-dimensional lists (arrays)
Two-dimensional lists (arrays) - Learn Python 3 - Snakify
For example, suppose you need to ... and the element with row index i and column index j is calculated by the formula a[i][j] = i * j....
🌐
Scaler
scaler.com › home › topics › 2d array in python
2D Array in Python | Python Two-Dimensional Array - Scaler Topics
October 10, 2025 - Where array_name is the array's name, r1c1, r1c1 etc., are elements of the array. Here r1c1 means that it is the element of the first column of the first row. A 2D array is an array of arrays.
🌐
Reddit
reddit.com › r/learnprogramming › loop 2d (or more) array by column instead of row first?
r/learnprogramming on Reddit: Loop 2d (or more) array by column instead of row first?
January 18, 2024 -

It is said we can loop through 2d matrix by rows or by columns (in algo or python) … I think that the first indice in array is row.[…] … … I give example of stackoverflow link https://stackoverflow.com/questions/10148818/numpy-how-to-iterate-over-columns-of-array, but they said it is because it is Numpy. …

https://imgur.com/Vzk3Cef this is how I learn.

Here in java

int[][] twoDArray = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; System.out.println(twoDArray[1][2]);

Output:

6

If i consider searching by column, the output will be 8. That is what i mean by loop through column first. …

Am i really wrong???

Top answer
1 of 5
4
But I am really wrong??? Wrong about what? I don't understand exactly what your disagreement with your teacher is. A teacher (python) tells that we can loop through 2d matrix by rows or by columns (in algo or python) Are you trying to say you disagree that it's possible to loop through a 2D array first by columns and then by rows? It's definitely possible. Just loop over the column indices in the outer loop, and the row indices in the inner loop. Also, they said array[j][i]==array[i][j] in their explanation. Well, obviously that's not true in general. If array[i][j] is a valid array element, then array[j][i] might not even be inside the bounds of the array (if it's not a square array). I give example of stackoverflow link https://stackoverflow.com/questions/10148818/numpy-how-to-iterate-over-columns-of-array , but they said it is because it is Numpy. Yes, most of the answers in that thread are specific to Numpy arrays and will not work on a standard Python list-of-lists. I try their solution and it fails. Teacher is sure it will work even if i try to show the issue. What solution is this? Without seeing the code, I don't see how anyone can tell you if it's correct or not.
2 of 5
3
You can decide whether the first dimension represents rows or columns (the second dimension would be whatever you didn't pick first), as long as you use the same convention consistently. You can view a matrix as an array of rows but also as an array of columns, both choices make sense. Numpy has already made its choice, so if you interact with numpy you kind of have to make the same choice (or you have to work around the difference otherwise). When it comes to looping over a matrix, you can of course do it row-by-row or column-by-column independently of which order you chose to store the matrix in. One order may be somewhat more natural than the other, but they're both possible.
🌐
DEV Community
dev.to › drvcodenta › accessing-rows-and-columns-in-a-2d-array-and-insert-methodpython-2plo
accessing rows and columns in a 2d array and insert method(python) - DEV Community
March 17, 2024 - Accessing a row: To access a row in a 2D array, you only need one index. For example, matrix[i] will give you the ith row. Accessing a column: Accessing a column is a bit trickier because Python's list of lists structure does not have built-in ...
🌐
NumPy
numpy.org › devdocs › user › absolute_beginners.html
NumPy: the absolute basics for beginners — NumPy v2.5.dev0 Manual
Using np.newaxis will increase the dimensions of your array by one dimension when used once. This means that a 1D array will become a 2D array, a 2D array will become a 3D array, and so on. ... You can explicitly convert a 1D array to either a row vector or a column vector using np.newaxis.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › home › python_data_structure › python 2d array
Python 2D Array
February 21, 2009 - Two dimensional array is an array within an array. It is an array of arrays. In this type of array the position of an data element is referred by two indices instead of one. So it represents a table with rows an dcolumns of data.
🌐
DataCamp
campus.datacamp.com › courses › intro-to-python-for-data-science › chapter-4-numpy
2D NumPy Arrays | Python
You want both rows, so you put in a colon before the comma. You only want the second and third column, so you put in the indices 1 to 3 after the comma. Remember that the third index is not included here. The intersection gives us a 2D array with 2 rows and 2 columns: Similarly, you can select the weight of all family members like this: you only want the second row, so put 1 before the comma.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-retrieve-an-entire-row-or-column-of-an-array-in-python
How to Retrieve an Entire Row or Column of an Array in Python? - GeeksforGeeks
July 23, 2025 - When you slice a specific row or column, NumPy may return it as a 2D array. np.squeeze() removes any unnecessary dimensions, giving you a clean 1D array. ... import numpy as np a = np.array([[1, 2, 3],[4, 5, 6],[7, 8, 9]]) r = np.squeeze(a[1:2, ...
🌐
Cf
physics-python.astro.cf.ac.uk › Week6
PX1224 -Week6: Two Dimensional Arrays
A 2D array can be "sliced" to return a 1D array containing one row or column of the original. So, for example, the zeroth (Python starts array with index 0) row or column is given by
🌐
Medium
medium.com › @izxxr › 2d-arrays-in-python-08ff7c287b2a
2D Arrays in Python. 2D arrays, also known as a matrix, are… ...
September 7, 2024 - The nested lists represent the rows and the elements of the nested lists are the columns. To access an element of a 2D array, we first index the table array to get a specific row and then we index that row to get a specific element.
🌐
Google
sites.google.com › rgc.aberdeen.sch.uk › rgcahcomputingrevision › software-design › data-types-and-structures › 2d-arrays
Advanced Higher Computing Revision - 2D Arrays
Python treats this as a list within a list. You will notice that we have initialised each element in the array with a value of 0. This would create a 2D array called my2dArray with 3 rows and 8 columns.
🌐
Drbeane
drbeane.github.io › python_dsci › pages › array_2d.html
2-Dimensional Arrays — Python for Data Science
Notice that the array that is printed above is not displayed in the form of a column. In fact, when slicing a single row or a column out of a 2D array, the result is returned as a simple 1D array.
🌐
W3docs
w3docs.com › python
How do you extract a column from a multi-dimensional array?
In Python, you can extract a column from a multi-dimensional array (e.g. a 2D numpy array) by indexing it using the column number. For example, if you have a 2D numpy array called arr, you can extract the i-th column by using the following code ...
🌐
Sanshaacademy
sanshaacademy.com › python › ds › two_d_array.php
Python Two Dimension Array
# Creating a 2D array (list of lists) matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] # Accessing elements print(matrix[0][1]) # Output: 2 (row 0, column 1) # Modifying an element matrix[1][2] = 10