In this python numpy program, we will access an array by column using NumPy.
Steps to solve the program
- Import the numpy library as np.
- Create an array using np.array().
- Access an array by column using indexing (i.e. array[row, column] ) and logic.
- Print the output.
import numpy as np
x = np.array([[4,8,0],[2,0,6]])
print("1st column: \n",x[:,0])
print("2nd column: \n",x[:,1])
print("3rd column: \n",x[:,2])
Output :
1st column:
[4 2]
2nd column:
[8 0]
3rd column:
[0 6]