Table of Contents

				
					import numpy as np
				
			
				
					# Example 1: Matrices from Slide 6
A1 = np.array([[2, 0], [1, 3]])
				
			
				
					B1 = np.array([[1, 4], [2, 5]])
				
			
				
					C1 = np.dot(A1, B1)  # Perform matrix multiplication
				
			
				
					print(C1)
				
			
				
					C1v2 = A1.dot(B1)
				
			
				
					print(C1v2)
				
			
				
					# Example 2: Random number problem matrices
A2 = np.array([[7, 4, 8], [5, 7, 3]])
				
			
				
					B2 = np.array([[7, 8], [5, 4], [8, 8]])
				
			
				
					C2 = np.dot(A2, B2)  # Perform matrix multiplication
				
			
				
					print(C2)
				
			
				
					# Function to check if two matrices can be multiplied
def can_multiply(mat1, mat2):
    if mat1.shape[1] == mat2.shape[0]:
        result_size = (mat1.shape[0], mat2.shape[1])
        print(f"Matrices of shapes {mat1.shape} and {mat2.shape} CAN be multiplied.")
        print(f"The resulting matrix will have dimensions: {result_size}")
        return result_size
    else:
        print(f"Matrices of shapes {mat1.shape} and {mat2.shape} CANNOT be multiplied.")
        return None
				
			
				
					# Example usage of the function
print("\nCan A1 and B1 be multiplied?")
can_multiply(A1, B1)
				
			
				
					print("\nCan A2 and B2 be multiplied?")
can_multiply(A2, B2)
				
			

Free Community

Join 1,000+ AI Automation Builders

Weekly tutorials, live calls & direct access to Ryan & Matt.

Join Free →

Keep Learning

Python Reduced Row Echelon Form

https://youtu.be/12hpWB3cmzg From REF to RREF

Python Augmented Matrix

https://youtu.be/wDrAPOPUIMY Example 1 Example 2 row operations Multiply the first row by 3 add: 2nd row to the first subtract 2nd row...

Inverse Matrix

https://youtu.be/wfHaKrmMbFk 2x2 example 3x3 example properties A^-1 * A = A * A^-1 = I (AB)^−1=B^−1A^−1 (A^T)^−1=(A^−1)^T (kA)^−1=(1/k)(​A^−1) (A^−1)^−1=A

Python Identity Matrix

https://youtu.be/Jeu9Fkfh9Hw Example 1 Create a 3x3 identity matrix also can use np.eye Example 2 Matrix Multiplication Example 3 Determinant of the Identity...