-4

I am new to programming and want to write the following equation in Python.

enter image description here

Alec
  • 8,529
  • 8
  • 37
  • 63
Yousef
  • 1
  • 2
    [Double Summation in Python](https://stackoverflow.com/questions/19274813/double-summation-in-python) – takendarkk Apr 25 '19 at 19:09
  • Possible duplicate of [Double Summation in Python](https://stackoverflow.com/questions/19274813/double-summation-in-python) – sanyassh Apr 25 '19 at 19:13
  • yes. i see this post. however, my equation has 3 matrcies x, t, and x. Also it multiply x, t and i. could one give an example. – Yousef Apr 25 '19 at 19:16
  • 1
    elcome to SO. Please take the time to read [ask] and the other links found on that page. Invest some time with [the Tutorial](https://docs.python.org/3/tutorial/index.html) practicing the examples. It will give you an idea of the tools Python offers to help you solve your problem. – wwii Apr 25 '19 at 19:20

1 Answers1

-1

basically, it's just a double for loop (nested loop), a for loop within a for loop

def tau(i, J, K):
  total = 0
  for j in J:
    for k in K:
      total += y(i, j)*t(j,k)*x(i,k)
  return total

of course, you can collapse this to a few lines by using reduce and list comprehension. You might want to look those up if this is the first time you're hearing about them

BTW, I'm assuming you want vanilla python. If you're dealing with matrices, please look at the numpy library