← Problems

2. Dot Product

EasyVectorsLinear AlgebraNumPy

Given two vectors a\mathbf{a} and b\mathbf{b} of equal length, return their dot product.

The dot product is defined as:

ab=i=1naibi\mathbf{a} \cdot \mathbf{b} = \sum_{i=1}^{n} a_i b_i

Where nn is the length of each vector.

Example

a = [1, 2, 3] b = [4, 5, 6] Output: 32 # (1×4 + 2×5 + 3×6)

Constraints

  • You may use NumPy or pure Python.
  • Both inputs will always have the same length.
Python 3
⌘ + Enter
Run your code to see results
Ctrl + Enter