How to extract a column from a multi-dimensional numpy array in Python

2 Answers

0 votes
import numpy as np
 
arr = np.array([[1, 2, 3], 
                [4, 5, 6], 
                [7, 8, 9], 
                [10, 11, 12]])

column_1 = arr[:, 1]

print(column_1)



'''
run:

[ 2  5  8 11]

'''

 



answered Dec 15, 2023 by avibootz
0 votes
import numpy as np
 
arr = np.array([[1, 2, 3], 
                [4, 5, 6], 
                [7, 8, 9], 
                [10, 11, 12]])

column_1 = np.take(arr, 1, axis=1)

print(column_1)



'''
run:

[ 2  5  8 11]

'''

 



answered Dec 15, 2023 by avibootz
...