I need to loop through ( list and array) as below
f=[2,3]
b=np.array([1,2],[2,3])
total=(f[0]*(b[0][0] b[0][1]) (f[1]*(b[1][0] b[1][1])
I want to do this using loop with sum, because the actual equation is more complicated.
so total=sum(F*(b b))
How can this be done?
CodePudding user response:
If you need to generalise dimensions of an array, you can use the ':
' index. For example,
total = 0
for i in range(2):
total = f[i]*sum(b[i,:])
I'll leave this here as well: Understanding slice notation