Program to create a 2×2 matrix using NumPy.

In this python numpy program, we will create a 2×2 matrix using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array of 4 elements using np.array() because 2×2 matrix will have 4 elements.
  3. Now convert the array to create a 2×2 matrix using reshape.
  4. Print the output.
				
					import numpy as np
x = np.arange(4)

x.reshape(2,2)
				
			

Output :

				
					array([[0, 1],
       [2, 3]])
				
			

create a 2×3 matrix.

create a vector with values from 1 to 15 and change the sign of the numbers in the range from 6 to 10.

Leave a Comment