w3resource logo
Python Exercises

Python NumPy: Access an array by column

Python NumPy: Array Object Exercise-81 with Solution

Write a Python program to access an array by column.

Sample Solution:-

Python Code:

import numpy as np
x= np.arange(6).reshape(3, 2)
print("Original array elements:")
print(x)
print("Access an array by column:")
print("First column:")
print(x[0,:])
print("Second column:")
print(x[1,:])
print("Third column:")
print(x[2,:])

Sample Output:

Original array elements:                                               
[[0 1]                                                                 
 [2 3]                                                                 
 [4 5]]                                                                
Access an array by column:                                             
First column:                                                          
[0 1]                                                                  
Second column:                                                         
[2 3]                                                                  
Third column:                                                          
[4 5]

Python Code Editor:

Improve this sample solution and post your code through Disqus.

New exercises: Matplotlib: Exercises, Practice, Solution