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 › 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 - import numpy as np a = np.array([[1, 2, 3],[4, 5, 6],[7, 8, 9]]) r = np.squeeze(a[1:2, :]) c = np.squeeze(a[:, 2:3]) print(r, c) ... If you're not using NumPy or you're working with pure Python lists, you can manually loop through rows to get a specific column. It's slower and not recommended for large data, but it's good for understanding how things work under the hood.
🌐
Medium
medium.com › @linuxrootroom › python-row-and-column-major-multidimensional-array-8ce9f0cf78dd
Python: Row and Column Major Multidimensional Array | by Linux Root Room | Medium
July 26, 2024 - import numpy as np # Create a 2D array with shape (3, 4) arr = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]) print(arr) # Flatten the array to 1D and print its contents flat_arr = arr.flatten() print(flat_arr) # Access an element by specifying its row and column indices elem = arr[1, 2] print(elem)
🌐
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 - For example, [row[j] for row in matrix] will give you the jth column. Suppose you want to access all of the items present in one row of a 2-dimensional array or a matrix and change it to some value(let's say 0 to 1), then you can do it this way: // creating a matrix initializing 0 at all of the indices · matrix = [[0]*n for i in range(m)] # n = number of cells in a row or number of columns and m = number of rows for i in range(n): matrix[row_number][i] = 1
🌐
Kitchin Research Group
kitchingroup.cheme.cmu.edu › blog › 2013 › 02 › 26 › Creating-arrays-in-python
Creating arrays in python - The Kitchin Research Group
February 26, 2013 - We index an array by [row, column]. To get a row, we specify the row number, and all the columns in that row like this [row, :]. Similarly, to get a column, we specify that we want all rows in that column like this: [:, column]. This approach is useful when you only want a few columns or rows.
🌐
TutorialsPoint
tutorialspoint.com › article › 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?
March 27, 2026 - array_name[row_index, column_index] # For entire row: array_name[row_index, :] # For entire column: array_name[:, column_index] Here we create a 2D array and retrieve the second row (index 1) and second column (index 1) using slice notation ?
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › find-the-number-of-rows-and-columns-of-a-given-matrix-using-numpy
Find the number of rows and columns of a given matrix using NumPy - GeeksforGeeks
April 18, 2026 - Indexing can be used to obtain the number of rows and columns by accessing the elements of the .shape tuple. ... import numpy as np m = np.array([[4, 3, 2], [8, 7, 6]]) rows = m.shape[0] cols = m.shape[1] print("Rows:", rows) print("Columns:", cols)
🌐
MachineLearningMastery
machinelearningmastery.com › home › blog › how to set axis for rows and columns in numpy
How to Set Axis for Rows and Columns in NumPy - MachineLearningMastery.com
August 23, 2020 - a lot more efficient than simply Python lists. NumPy arrays are called NDArrays and can have virtually any number of dimensions, although, in machine learning, we are most commonly working with 1D and 2D arrays (or 3D arrays for images). For example, we can convert our list of lists matrix to a NumPy array via the asarray() function: We can print the array directly and expect to see two rows of numbers, where each row has three numbers or columns.
🌐
Learning About Electronics
learningaboutelectronics.com › Articles › How-to-change-the-number-of-rows-and-columns-in-an-array-in-Python.php
How to Change the Number of Rows and Columns in an Array in Python
We then output the contents of this reshaped array which has 8 rows and 5 columns. We then reshape the array again, this time into 10 rows that each contain 4 columns. We then reshape the array into 4 rows containing 10 columns each. So using the reshape() function in Python, we are able to change the number of rows and columns in an array in Python.
🌐
Learning About Electronics
learningaboutelectronics.com › Articles › How-to-retrieve-an-entire-row-or-column-of-an-array-in-Python.php
How to Retrieve an Entire Row or Column of an Array in Python
In this case, we want to retrieve all of the elements in row 2. To get all of the elements in a column, we use the format, arrayname[row_number,:], where arrayname is the name of the array and row_number is the number of the row whose contents you want to retrieve.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-ways-to-add-row-columns-in-numpy-array
Ways to Add Row/Columns in Numpy Array - Python - GeeksforGeeks
June 24, 2025 - We can add columns to a NumPy array using append(), concatenate(), insert(), column_stack() or hstack() with axis=1. Just make sure the new column has the same number of rows as the original array. np.append() adds values to a NumPy array along ...
🌐
GeeksforGeeks
geeksforgeeks.org › python-ways-to-add-row-columns-in-numpy-array
Python | Ways to add row/columns in numpy array - GeeksforGeeks
March 22, 2023 - import numpy as np ini_array = np.array([[1, 2, 3], [45, 4, 7], [9, 6, 10]]) # Array to be added as row row_to_be_added = np.array([1, 2, 3]) # Adding row to numpy array result = np.vstack ((ini_array, row_to_be_added) ) # printing result print ...