I have a function I am using to convert some numbers into a different form that requires iterating over a couple of arrays. I used two nested for loops but the results are not what I expected. I want the function to return a total of 5 variables but it returns number of variables in each array multiplied by each other. So in the following case it returns an array of 25 variables.
co_60_activities = [2 , 2 , 3 , 3 , 3]
co_60_masses = [2 , 2 , 3 , 3 , 3]
def activity(activities, masses, array):
for x in range(len(activities)):
for y in range(len(masses)):
array.append(activities[x] * masses[y] * 37000.0)
a_counts = []
activity(co_60_activities, co_60_masses, a_counts)
I found in similar posts that the conventional way to iterate through multiple lists is to use the zip function. So I changed my function to the following:
def activity(activities, masses, array):
for x , y in zip(activities , masses):
array.append(activities[x] * masses[y] * 37000.0)
This yields a "TypeError: list indices must be integers, not float" I assume I need to convert the data type somehow but I am not sure how.