1# A basic code for matrix input from user
2
3R = int(input("Enter the number of rows:"))
4C = int(input("Enter the number of columns:"))
5
6# Initialize matrix
7matrix = []
8print("Enter the entries rowwise:")
9
10# For user input
11for i in range(R): # A for loop for row entries
12 a =[]
13 for j in range(C): # A for loop for column entries
14 a.append(int(input()))
15 matrix.append(a)
16
17# For printing the matrix
18for i in range(R):
19 for j in range(C):
20 print(matrix[i][j], end = " ")
21 print()
1import numpy
2# Two matrices are initialized by value
3x = numpy.array([[1, 2], [4, 5]])
4y = numpy.array([[7, 8], [9, 10]])
5# add()is used to add matrices
6print ("Addition of two matrices: ")
7print (numpy.add(x,y))
8# subtract()is used to subtract matrices
9print ("Subtraction of two matrices : ")
10print (numpy.subtract(x,y))
11# divide()is used to divide matrices
12print ("Matrix Division : ")
13print (numpy.divide(x,y))
14print ("Multiplication of two matrices: ")
15print (numpy.multiply(x,y))
16print ("The product of two matrices : ")
17print (numpy.dot(x,y))
18print ("square root is : ")
19print (numpy.sqrt(x))
20print ("The summation of elements : ")
21print (numpy.sum(y))
22print ("The column wise summation : ")
23print (numpy.sum(y,axis=0))
24print ("The row wise summation: ")
25print (numpy.sum(y,axis=1))
26# using "T" to transpose the matrix
27print ("Matrix transposition : ")
28print (x.T)