Posts

Showing posts with the label Dot Product

Linear Algebra with NumPy: Dot Products & Matrix Multiplication

Linear Algebra with NumPy: Dot Products & Matrix Multiplication Linear algebra is fundamental to data science, machine learning, and scientific computing. NumPy provides powerful tools for efficient linear algebra operations. Today, we'll focus on two core concepts: dot products and matrix multiplication. 1. Dot Product (Vector Dot Product) The dot product (or scalar product) of two vectors is a single number. It's calculated by multiplying corresponding elements and summing the results. Geometrically, it relates to the angle between vectors. 1D Arrays (Vectors): Python import numpy as np v1 = np.array([ 1 , 2 , 3 ]) v2 = np.array([ 4 , 5 , 6 ]) # Using np.dot() dot_product = np.dot(v1, v2) print( "Vector Dot Product (np.dot):" , dot_product) # Output: 32 (1*4 + 2*5 + 3*6) # Using the @ operator (Python 3.5+) dot_product_at = v1 @ v2 print( "Vector Dot Product (@ operator):" , dot_product_at) # Output: 32 2. Matrix Multiplication Matrix multipli...