Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs

Back to Questions

133. Vector multiplication

easy
GeneralGeneral
senior

Vector multiplication is a core linear algebra operation used in ML for computing projections and model scores. In this task, you’ll implement the dot product of two vectors.

The dot product is defined as:

x⋅y=∑i=1nxiyix \cdot y = \sum_{i=1}^{n} x_i y_i

Requirements

Implement the function

python

Rules:

  • Compute and return a single float value equal to the dot product of x and y.
  • Do not use prebuilt dot-product helpers (e.g., numpy.dot, @, numpy.matmul).
  • You may use NumPy for basic elementwise multiplication (*) and summation (sum).
  • Aim for clean, vectorized code.

Example

python

Output:

python
Input Signature
ArgumentType
xnp.ndarray
ynp.ndarray
Output Signature
Return NameType
valuefloat

Constraints

  • No numpy.dot/@/matmul allowed

  • Return a single float result

  • Keep solution inside dot_product()

Hint 1

This can be done with elementwise multiplication x * y followed by np.sum(...).

Hint 2

Ensure you return a native python float, e.g. float(np.sum(...)).

Roles
ML Engineer
AI Engineer
Data Scientist
Quantitative Analyst
Companies
GeneralGeneral
Levels
senior
entry
Tags
dot-product
loops
linear-algebra
time-complexity
35 people are solving this problem
Python LogoPython Editor
Ln 1, Col 1

Input Arguments

Edit values below to test with custom inputs

You need tolog in/sign upto run or submit