Program to access two columns of a NumPy array

In this python numpy program, we will access two columns of a NumPy array.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Use for loop to iterate over the first two rows of the array.
  4. Access the first two columns of the array using indexing.
  5. Print the output.
				
					import numpy as np
x = np.array([[6, 5, 7],[10, 9, 1],[7, 8, 2]])

for i in range(0,2):
    print(f"{i+1} column: ",x[:,i])
				
			

Output :

				
					1 column:  [ 6 10  7]
2 column:  [5 9 8]
				
			

convert an array into a CSV file.

extract the first and second elements of the first and second rows from a given (3×3) matrix.

Leave a Comment