Back to Practice
#0153
Batch Dot Products
MediumNumPy25 min20 XP
Problem
Given a 2D matrix X and vector w, return the dot product of each row of X with w.
Why This Matters
Batch dot products appear in similarity search, linear models, attention scores, and embedding comparisons.
Function Signature
def batch_dot(X, w):
Examples
Example 1
InputX = np.array([[1,2],[3,4]]), w = np.array([10,1])
Outputnp.array([12, 34])
Rows produce 1*10+2*1=12 and 3*10+4*1=34.
Constraints
- Return the exact requested value.
- Handle empty or small inputs when the prompt allows them.
- Keep the code readable and deterministic.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
InputX = np.array([[1,2],[3,4]]), w = np.array([10,1])
Expectednp.array([12, 34])
Rows produce 1*10+2*1=12 and 3*10+4*1=34.
Hidden Test Categories
empty or smallest inputduplicates or repeated valueslarger realistic input