In this python numpy program, we will multiply a row of an array by a scalar using NumPy
Steps to solve the program
- Import the numpy library as np.
- Create an array using np.array().
- Multiply a row of an array by a scalar using Indexing and logic.
- 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]]