Program to swap rows of a given array using NumPy.

In this python numpy program, we will swap rows of a given array using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Swap rows of a given array using Indexing and logic.
  4. Print the output.
				
					import numpy as np
x = np.array([[6, 5],
              [10, 9],
              [8, 7]])
print("Original array: ",x)
print("After swapping")
new = print(x[::-1, :])
				
			

Output :

				
					Original array:  [[ 6  5]
 [10  9]
 [ 8  7]]
After swapping
[[ 8  7]
 [10  9]
 [ 6  5]]
				
			

replace all numbers in a given array that is equal or greater than a given number.

multiply a row of an array by a scalar.

Leave a Comment