Vector Times Matrix X45739


Statement
 

pdf   zip   main.py

Write a function v_times_m(v,m)v\_times\_m(v, m) that receives a vector (in the form of a tuple) of floats and a matrix of floats mm, 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 vv is not zero and that it equals the lengths of all the columns of mm. The returned vector is to be a tuple of the same length as the rows of mm, 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