Let's say I have 3 lists
a = [1.12, 2.23, 3.34]
b = [2.12, 3.23, 4.34]
c = [3.12, 4.23, 5.34]
my goal is to round the numbers down to 1 decimal. so I have this custom function:
import math
def round_down(n, decimals=0):
multiplier = 10 ** decimals
return math.floor(n * multiplier) / multiplier
May I ask what is the most efficient way of operating on each element in each object? In this easy example I could write a loop for each of the 3 objects, such as:
for i in np.range(len(a)):
a[i] = round_down(a[i], decimals=1)
However, in my work, I have many more lists of various lengths and I really don't want to code them one by one. Is there a way to iterate through a list of objects? or process them in parallel?