I'm trying to make a list by using other lists as arguments of a function. However, i can't seem to get the right syntax.
This is my code:
f1 = theta0 + theta1*(X1_train) + theta2*(X2_train)+theta3*(X3_train)
The expected outcome would be a list of the same length of X1_train, X2_train and X3_train (which is the same for those 3).
I expect to get a list of the outcomes of each element on the lists X1_train, X2_train and X3_train as arguments of the funcion. For example, if my lists were
X1_train = [0, 1]
X2_train = [1, 2]
X3_train = [0, 2]
I'd expect a list of numbers like
f1 = [theta0 + theta2, theta0 + theta1 + theta2 + 2*theta3]
The thethas are random numbers.
This lists are columns of a dataframe I converted into lists so I could do the function.
I hope this helps:
import random
X1_train = [0,1]
X2_train = [1,2]
X3_train = [0,1]
amnt = 2
theta0 = random.sample(range(1, 10), amnt)
theta1 = random.sample(range(1, 10), amnt)
theta2 = random.sample(range(1, 10), amnt)
theta3 = random.sample(range(1, 10), amnt)
EndValues = []
for i in range(0, len(X1_train)):
f1 = theta0[i] + theta1[i] * X1_train[i] + theta2[i] * X2_train[i] + theta3[i] * X3_train[i]
EndValues.append(f1)
print(EndValues)
This returns
[3, 6] [5, 1] [2, 5] [7, 8]
[5, 25]