understanding matrix problems in python code example
Example 1: how to get matrix element in the form of matrix in python
R = int(input("Enter the number of rows:"))
C = int(input("Enter the number of columns:"))
matrix = []
print("Enter the entries rowwise:")
for i in range(R):
a =[]
for j in range(C):
a.append(int(input()))
matrix.append(a)
for i in range(R):
for j in range(C):
print(matrix[i][j], end = " ")
print()
Example 2: python matrix algorithms
import numpy
x = numpy.array([[1, 2], [4, 5]])
y = numpy.array([[7, 8], [9, 10]])
print ("The element wise square root is : ")
print (numpy.sqrt(x))
print ("The summation of all matrix element is : ")
print (numpy.sum(y))
print ("The column wise summation of all matrix is : ")
print (numpy.sum(y,axis=0))
print ("The row wise summation of all matrix is : ")
print (numpy.sum(y,axis=1))
print ("The transpose of given matrix is : ")
print (x.T)