-1

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?

dbc
  • 104,963
  • 20
  • 228
  • 340
Zain
  • 3
  • 1

1 Answers1

0

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

  • no it is not dot or @ multiplication . how I can do it in away that the python will take the first element in the F and understand the b is b from first list and for second element in F will use the second list – Zain Nov 28 '21 at 09:32
  • I edited my answer, I hope this is what you need. – Themistoklis Gkasios Nov 28 '21 at 10:05