I have a list of sublists, such as this:
t = [ [1, 2, 3, 4], [2, 5, 7, 9], [7, 9, 11, 4] ]
I want to multiply each of the sublists by a list such that the first item in each sublist is multiplied by the first item in the multiplier list, the second item in each sublist is multiplied by the second item in the multiplier list, etc. The multiplier list is:
multiplier = [0.1, 0.3, 0.5, 0.8]
So that the ultimate result would be something like:
result = [ [0.1, 0.6, 1.5, 3.2], [0.2, 1.5, 3.5, 7.2], [0.7, 2.7, 5.5, 3.2] ]
How do I do this? I'm sorry if this question has been asked, I've been searching for hours and haven't found something that precisely applies.
or just one line
total_result
numpy
(Numpy)would handle all this:Numpy would probably be the easiest solution, but if you wanted to do without:
map
calls themult_lists
function for each item int
, then it is arranged in a list.You can use list comprehension:
For clarity, expanded iterative version is:
...
Actually, numpy makes it easier: