How can I divide list's element's by an integer ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I divide list's element's by an integer ?

a = [1,4,8,10] / 10 I want this result: [0.1,0.4,0,8,1.0]

24th May 2020, 8:55 AM
Gökhan TUNCER
Gökhan TUNCER - avatar
3 Answers
+ 4
Consider using numpy module: import numpy as np a = np.array([1,4,8,10]) / 10 print(a) Or if you really need lists, you have to make calculactions in an iterative way: a = [x/10 for x in [1, 4, 8, 10]] print(a)
24th May 2020, 9:07 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
My way not as clever as Kuba. a = [1,4,8,10] #I want this result: #[0.1,0.4,0.8,1.0] output = [] for i in a: division = i/10 output.append(division) print(output)
24th May 2020, 9:26 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Thank you I want to normalization to list norm_a = [float(i)/max(i) for i in a] It's done
24th May 2020, 9:14 AM
Gökhan TUNCER
Gökhan TUNCER - avatar