PIXELBANKv8.2.1
Menu

Dot Product

Problem Statement

Compute dot products and matrix multiplications.

Background

NumPy provides several multiplication operations:

  • np.dot(a, b) - dot product
  • a @ b - matrix multiplication (Python 3.5+)
  • a * b - element-wise multiplication

For vectors: dot product = sum of element-wise products For matrices: standard matrix multiplication

Your Task

Write a function compute_products(vec1, vec2, mat) that computes various products.

Output Format

Return a dictionary with:

  • "dot": Dot product of vec1 and vec2 (scalar)
  • "elementwise": Element-wise product of vec1 and vec2 (list)
  • "mat_vec": Matrix times vec1 (list)
  • "vec_mat": vec1 times matrix (list)

Example:

Input:
vec1 = [1,2,3], vec2 = [4,5,6], mat = identity
Output:
{'dot': 32, 'elementwise': [4, 10, 18], 'mat_vec': [1, 2, 3], 'vec_mat': [1, 2, 3]}
Reasoning:

Dot: 14+25+36=32, elementwise: [14, 25, 36], identity matrix preserves vectors

Constraints:

  • vec1 and vec2 have same length
  • mat is square with size matching vector length
Editor

Test Results

0/0
Run code to see test results.