Examples of Matrices operations in Python Programming
All Contributions
Python program explaining numpy.matlib.eye() function
# importing matrix library from numpy
import numpy as np
import numpy.matlib
# desired 3 x 3 output matrix
out_mat = np.matlib.eye(3, k = 0)
print ("Output matrix : ", out_mat)
Transpose of a Matrix
We use numpy.transpose to compute transpose of a matrix :
import numpy as np
A = np.array([[1, 1], [2, 1], [3, -3]])
print(A.transpose())
Multiplication of Two Matrices
To multiply two matrices, we use dot() method :
import numpy as np
A = np.array([[3, 6, 7], [5, -3, 0]])
B = np.array([[1, 1], [2, 1], [3, -3]])
C = A.dot(B)
print(C)
total contributions (5)
Python program explaining numpy.matlib.identity() function