title: How to sum over two indices in python?
body: <p>Can someone help me out with the <code>sum</code> function ?</p>
  
  <p>I am trying to sum over two indices. I want to obtain the following result:</p>
  
  <pre><code>p_t[0, 0]+p_t[0, 1]+p_t[0, 2]+p_t[1, 0]+p_t[1, 1]+p_t[1, 2]+p_t[2,0]+p_t[2, 1]+p_t[2, 2]
  </code></pre>
  
  <p>, using this code:</p>
  
  <pre><code>num_products=3
  sum (p_t[i, j] for i,j in range(num_products))
  </code></pre>
  
  <p>But I get the error:</p>
  
  <blockquote>
    <p>TypeError  Traceback (most recent call last)
         in ()
        ----> 1 sum (p_t[i, j] for i,j in range(num_products))
         in (<strong><em>failed resolving arguments</em></strong>)
        TypeError: 'int' object is not iterable</p>
  </blockquote>
  
  <p>I also tried this but did not work either</p>
  
  <pre><code>sum (p_t[i, j] for i in range(num_products) for j in range(num_products))
  </code></pre>