concept
Vectors and dot products
Equal-length aligned vectors: multiply corresponding entries and sum; distinguish scalar score and elementwise product.
Formal Syntax & Structure
artificial-intelligence syntaxartificial-intelligence
Vectors and dot productsWorking Example
Example Snippetartificial-intelligence
def dot(a, b): if len(a) != len(b) or not a: raise ValueError("Use equal, nonempty vectors") total = 0 for i in range(len(a)): total += a[i] * b[i] return total
print(dot([2, 3], [4, 1]))print(dot([1, -2], [3, 4]))print(dot([0, 0], [4, 1]))