With:

test = np.array([[1, 2], [3, 4], [5, 6]])

To access column 0:

>>> test[:, 0]
array([1, 3, 5])

To access row 0:

>>> test[0, :]
array([1, 2])

This is covered in Section 1.4 (Indexing) of the NumPy reference. This is quick, at least in my experience. It's certainly much quicker than accessing each element in a loop.

Answer from mtrw on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-access-a-numpy-array-by-column
How to access a NumPy array by column - GeeksforGeeks
June 26, 2025 - Slicing is the easiest and fastest way to access a specific column in a NumPy 2D array using arr[:, column_index], where : selects all rows and column_index picks the desired column.
Discussions

python - Numpy modify array in place? - Stack Overflow
I have the following code which is attempting to normalize the values of an m x n array (It will be used as input to a neural network, where m is the number of training examples and n is the number... More on stackoverflow.com
🌐 stackoverflow.com
Numpy: Iterate over Columns
Regular matrix multiplication will do what you want, though. The columns of A * B will be A applied to each column of B. More on reddit.com
🌐 r/Python
2
0
December 14, 2017
How to get only second column for the list
for foo, bar in data: print(bar) More on reddit.com
🌐 r/learnpython
15
2
July 16, 2022
read from csv file, then save both columns as x and y for numpy
You can use numpy’s genfromtxt function. import numpy as np cadeath = np.genfromtxt(‘cadeath.csv’, delimiter=‘,’ , skipheader=1) Then, all you have to do is subset by the second axis (the columns). X = cadeath[:, 0] y = cadeath[:, 1] Depending on what library you're using for the linear regression, you'll also probably have to convert the date to an integer value. More on reddit.com
🌐 r/learnpython
2
1
April 26, 2021
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-81.php
NumPy: Access an array by column - w3resource
August 29, 2025 - # Importing the NumPy library and aliasing it as 'np' import numpy as np # Creating a 1-dimensional array 'x' with values from 0 to 8 and reshaping it into a 3x3 array x = np.arange(9).reshape(3, 3) # Printing a message indicating the original array elements will be shown print("Original array elements:") # Printing the original array 'x' with its elements print(x) # Printing a message indicating that an array will be accessed by columns print("Access an array by column:") # Printing a message indicating the display of the first column of the array print("First column:") # Printing the first c
🌐
Statology
statology.org › home › how to get specific column from numpy array (with examples)
How to Get Specific Column from NumPy Array (With Examples)
September 16, 2021 - You can use the following syntax to get a specific column from a NumPy array: #get column in index position 2 from NumPy array my_array[:, 2]
🌐
TutorialsPoint
tutorialspoint.com › how-to-access-a-numpy-array-by-column
How to access a NumPy array by column?
Fancy indexing allows you to access multiple columns simultaneously by passing an array of column indices ? import numpy as np # Create a sample NumPy array array = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]) # Access columns at indices 1 and 3 columns = array[:, [1, 3]] print("Columns 1 and 3:") print(columns)
🌐
Delft Stack
delftstack.com › home › howto › numpy › numpy get column
How to Get Column of NumPy Array | Delft Stack
March 14, 2025 - Learn how to extract columns from a NumPy array in Python using basic slicing, the np.take function, and boolean indexing. This comprehensive guide provides clear examples and explanations to help you master data manipulation techniques with NumPy. Perfect for beginners and experienced programmers ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-iterate-over-columns-in-numpy
Python - Iterate over Columns in NumPy - GeeksforGeeks
February 26, 2023 - 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 ...
Top answer
1 of 4
33

If you want to apply mathematical operations to a numpy array in-place, you can simply use the standard in-place operators +=, -=, /=, etc. So for example:

>>> def foo(a):
...     a += 10
... 
>>> a = numpy.arange(10)
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> foo(a)
>>> a
array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19])

The in-place version of these operations is a tad faster to boot, especially for larger arrays:

>>> def normalize_inplace(array, imin=-1, imax=1):
...         dmin = array.min()
...         dmax = array.max()
...         array -= dmin
...         array *= imax - imin
...         array /= dmax - dmin
...         array += imin
...     
>>> def normalize_copy(array, imin=-1, imax=1):
...         dmin = array.min()
...         dmax = array.max()
...         return imin + (imax - imin) * (array - dmin) / (dmax - dmin)
... 
>>> a = numpy.arange(10000, dtype='f')
>>> %timeit normalize_inplace(a)
10000 loops, best of 3: 144 us per loop
>>> %timeit normalize_copy(a)
10000 loops, best of 3: 146 us per loop
>>> a = numpy.arange(1000000, dtype='f')
>>> %timeit normalize_inplace(a)
100 loops, best of 3: 12.8 ms per loop
>>> %timeit normalize_copy(a)
100 loops, best of 3: 16.4 ms per loop
2 of 4
13

This is a trick that it is slightly more general than the other useful answers here:

def normalize(array, imin = -1, imax = 1):
    """I = Imin + (Imax-Imin)*(D-Dmin)/(Dmax-Dmin)"""

    dmin = array.min()
    dmax = array.max()

    array[...] = imin + (imax - imin)*(array - dmin)/(dmax - dmin)

Here we are assigning values to the view array[...] rather than assigning these values to some new local variable within the scope of the function.

x = np.arange(5, dtype='float')
print x
normalize(x)
print x

>>> [0. 1. 2. 3. 4.]
>>> [-1.  -0.5  0.   0.5  1. ]

EDIT:

It's slower; it allocates a new array. But it may be valuable if you are doing something more complicated where builtin in-place operations are cumbersome or don't suffice.

def normalize2(array, imin=-1, imax=1):
    dmin = array.min()
    dmax = array.max()

    array -= dmin;
    array *= (imax - imin)
    array /= (dmax-dmin)
    array += imin

A = np.random.randn(200**3).reshape([200] * 3)
%timeit -n5 -r5 normalize(A)
%timeit -n5 -r5 normalize2(A)

>> 47.6 ms ± 678 µs per loop (mean ± std. dev. of 5 runs, 5 loops each)
>> 26.1 ms ± 866 µs per loop (mean ± std. dev. of 5 runs, 5 loops each)
🌐
Bobby Hadz
bobbyhadz.com › blog › numpy-iterate-over-columns-of-array
How to iterate over the Columns of a NumPy Array | bobbyhadz
April 12, 2024 - If you need to iterate over the columns of a three-dimensional array, use the following code sample instead. ... Copied!import numpy as np arr = np.array([[[1, 3, 5, 7], [2, 4, 6, 8]], [[3, 5, 7, 9], [4, 6, 8, 11]]], dtype=object) print(arr) print('-' * 50) for column in arr.transpose(1, 0, 2): print(column) print('-' * 50)
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-iterate-over-columns-in-numpy
How to iterate over Columns in Numpy
March 27, 2026 - import numpy as np # Create a 3x3 matrix arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) print("Iterating over columns using transpose:") # Transpose and iterate over each column for col in arr.T: print(col)
🌐
IncludeHelp
includehelp.com › python › numpy-how-to-iterate-over-columns-of-array.aspx
Python - NumPy: How to iterate over columns of array?
# Import numpy import numpy as np # Creating a numpy array arr = np.array([[3, 0, 4, 2, 3],[ 1, 5, 0, 6, 7],[ 4, 2, 0, 6, 7]]) # Display original array print("Original Array:\n",arr,"\n") # Accessing columns of arr i=1 for col in arr.T: print("Column ",i,":", col,"\n") i+=1
🌐
ProjectPro
projectpro.io › recipes › select-elements-from-numpy-array-in-python
How to Select Columns in NumPy Array using np.select? -
February 22, 2024 - You can use array slicing to select specific rows from a NumPy array. Slicing allows you to extract a portion of the array based on the indices of the rows you want to select. ... The expression arr[0:2, :] selects the first and second rows ...
🌐
Python Data Science Handbook
jakevdp.github.io › PythonDataScienceHandbook › 02.02-the-basics-of-numpy-arrays.html
The Basics of NumPy Arrays | Python Data Science Handbook
For example: ... One commonly needed routine is accessing of single rows or columns of an array. This can be done by combining indexing and slicing, using an empty slice marked by a single colon (:): ... One important–and extremely useful–thing to know about array slices is that they return views rather than copies of the array data. This is one area in which NumPy array slicing differs from Python list slicing: in lists, slices will be copies.
🌐
Reddit
reddit.com › r/python › numpy: iterate over columns
r/Python on Reddit: Numpy: Iterate over Columns
December 14, 2017 -

Hey,

I'm fairly new to Python and Numpy, but I have a reoccuring problem: I have a transformation matrix (as a numpy array) with a shape of (2,2) and a numpy array (shape(2,i)) with a lot of points I want to transform. In order to transform I need to get every column and multiply the transformation matrix with the column and then save the result in numpy array. I'm able to iterate over every column, however that doesn't look like the pythonic way to do it. Is there a short command or pythonic way?

🌐
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 - 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.
🌐
py4u
py4u.org › blog › how-to-access-a-numpy-array-by-column
How to Access a NumPy Array by Column: A Comprehensive Guide
NumPy arrays use 0-based indexing. Accessing a column index >= the number of columns raises an IndexError. ... try: arr_2d[:, 4] # arr_2d has 4 columns (indices 0-3) except IndexError as e: print(e) # Output: index 4 is out of bounds for axis 1 with size 4
🌐
Pdxdev
python.pdxdev.com › numpy › how-to-add-column-in-numpy-array
Mastering NumPy Array Manipulation
This will output an array of average grades for each student: ... Reshape the Averages: Reshape the averages array to match the desired column shape using [:, np.newaxis]. This adds a new dimension, effectively turning it into a column vector.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.column_stack.html
numpy.column_stack — NumPy v2.5 Manual
Try it in your browser! >>> import numpy as np >>> a = np.array((1,2,3)) >>> b = np.array((4,5,6)) >>> np.column_stack((a,b)) array([[1, 4], [2, 5], [3, 6]])