I want to get the sum of terms that put each element inside the list into a specific function f(x) in order.

Asked 2 years ago, Updated 2 years ago, 15 views

List = [element1, element2, ....., elementn ]

When there's a list like this

x0 = List[0]

x1 = List[1]

x2 = List[2]

.....

Like xn = list[n]

Xi = list[i] After each element of the list corresponds to the variable Xi,

When there is an arbitrary function f(X) (Assume that it is just the same as a simple polynomial function)

I want to get f(X0) + f(X1) + f(X2) +,,,, + f(Xn), but I don't know how to make f(Xi), which is the input for any Xi.

For reference, the elements values in the list are virtually any number without rules, so it can be considered that there is no regularity of the elements. I think I can do something about the rest with Sum if I just get the f(Xi) so what should I do???

I tried to define it by starting with fori in range(N): but it doesn't work...

Help me Python masters.ㅠ<

python

2022-09-22 13:43

1 Answers

x0 = List[0]
x1 = List[1]
x2 = List[2]
.....
xn = list[n]

If the input value is the same as above, you can pass the factor to the function as shown below.

sum=0
for i in range(N):
    sum += f(list[i])


2022-09-22 13:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.