Vector Times Matrix X45739


Statement
 

pdf   zip   main.py

html

Write a function v_times_m(v, m) that receives a vector (in the form of a tuple) of floats and a matrix of floats m, and returns the product of the vector by the matrix. The matrix is represented as a tuple of rows, each row being, in turn, a tuple of floats. We are guaranteed that the length of v is not zero and that it equals the lengths of all the columns of m. The returned vector is to be a tuple of the same length as the rows of m, which is also guaranteed to be nonzero.

Observation

Solutions that return other iterable types instead of tuples are vey likely to be accepted as well.

Sample session
>>> v_times_m( (1.5, 2.5),  ((10.5, 20.0, 30.0), (110.0, 120.0, 130.0)) )
(290.75, 330.0, 370.0)
>>> v_times_m( (5.0, 4.0, 3.0, 2.0),  ((1.0, 2.0), (10.0, 15.0), (20.0, 25.0), (30.0, 35.0)) )
(165.0, 215.0)
Information
Author
José Luis Balcázar
Language
English
Official solutions
Python
User solutions
Python