Matrix-Vector Dot Product

Matrix Algebra DS practice problem on Onlearn.

Difficulty: easy.

Topics: Understanding Matrix-Vector Dot Product, Matrix-Vector Multiplication, Scalar Product, Input Shape Validation, Nested Iteration, Error Handling Strategies, Linear Algebra, Numerical Computing, Programming Fundamentals, Algorithm Design, Data Structures, Matrix Operations, Vector Operations, Dimensionality Analysis, Function Design, Iterative Algorithms.

Write a Python function that computes the dot product of a matrix and a vector. The function should return a list representing the resulting vector if the operation is valid, or 1 if the matrix and vector dimensions are incompatible. A matrix (a list of lists) can be dotted with a vector (a list) only if the number of columns in the matrix equals the length of the vector. For example, an n x m matrix requires a vector of length m.