+ 1

I want each value in the matrix to be multiplied by the scalar

https://code.sololearn.com/cJLiiG05A48e/?ref=app

12th Jun 2022, 6:20 AM
Bernard Ocran
Bernard Ocran - avatar
4 Réponses
+ 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
12th Jun 2022, 6:50 AM
MATOVU CALEB
MATOVU CALEB - avatar
+ 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?
12th Jun 2022, 11:34 AM
Lothar
Lothar - avatar
+ 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
13th Jun 2022, 3:57 PM
Stefan Corneteanu
Stefan Corneteanu - avatar
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
12th Jun 2022, 8:32 PM
Simon Sauter
Simon Sauter - avatar