+ 1
I want each value in the matrix to be multiplied by the scalar
4 Answers
+ 5
In your code the for loop was looping through the 2 lists that were in the list m
https://code.sololearn.com/cJTIVEY0r8qK/?ref=app
+ 5
Bernard Ocran ,
what kind of output do you expect?
- print the calculated values?
- create a new output list?
- calculate the values and update the input list?
+ 1
Your for loop will itterate through your list and find that its elements are lists, not integers, and therefore the multiplication will not go as expected. Numpy is a solution but i will present an alternative: for each item of the list, check if the current item is a list. If yes, iterate through the list and perform the multiplication, else just perform the multiplication
0
You should look into numpy arrays. They make this kind of thing much easier and faster.
https://www.sololearn.com/learn/6671/?ref=app