Program to access an array by column using NumPy

In this python numpy program, we will access an array by column using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Access an array by column using indexing (i.e. array[row, column] ) and logic.
  4. 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]
				
			

print squares of all the elements of an array.

convert an array of float values to an array of integer values.

Leave a Comment