Skip to content
Advertisement

for loop only for a certain part of an equation in python

I would like to sum a function (in my case f = np.exp(x)) inside of an equation. I’m not sure if I am right to think like that but I think I saw my teacher do something like this once. Any idea how that would work? Here is the code:

JavaScript

where f(i) is my equation evaluated for every i in xi (which is a list of float)

JavaScript

Advertisement

Answer

Numpy allows calculation of element-wise exponential for an array. Thus you could simply do:

JavaScript

You could also keep what you have written and modify it as follows:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement