Program to multiply a row of an array by a scalar using NumPy

In this python numpy program, we will multiply a row of an array by a scalar using NumPy

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Multiply a row of an array by a scalar using Indexing and logic.
  4. Print the output
				
					import numpy as np
x = np.array([[6, 5],
              [10, 9],
              [8, 7]])
print("Original matrix: ",x)
x[0,:] = x[0,:]*2

print("After multiplyting first row by 2: ",x)
				
			

Output :

				
					Original matrix:  [[ 6  5]
 [10  9]
 [ 8  7]]
After multiplyting first row by 2:  [[12 10]
 [10  9]
 [ 8  7]]
				
			

swap rows of a given array.

add a row of a matrix into another row.

Leave a Comment