title: how to add list of arrays (tensors)
body: <p>I am defining a simple <code>conv2d</code> function to calculate the cross-correlation between input and kernel (both 2D tensor) as below:</p>
  
  <pre><code>import torch 
  
  def conv2D(X, K):
      h = K.shape[0]
      w = K.shape[1]
      ĥ = X.shape[0] - h + 1
      ŵ = X.shape[1] - w + 1
      Y = torch.zeros((ĥ, ŵ)) 
      for i in range (ĥ):
          for j in range (ŵ):
              Y[i, j] = (X[i: i+h, j: j+w]*K).sum()
  
      return Y 
  </code></pre>
  
  <p>When X and K are of rank-3 tensor, I calculate the conv2d for each channel and then add them together as below:</p>
  
  <pre><code>def conv2D_multiple(X, K):
      cross = []
      result = 0
      for x, k in zip(X, K):
          cross.append(conv2D(x,k))
  
      for t in cross:
          result += t
  
      return result 
  </code></pre>
  
  <p>To test my function:</p>
  
  <pre><code>X_2 = torch.tensor([[[0, 1, 2], [3, 4, 5], [6, 7, 8]], 
                      [[1, 2, 3], [4, 5, 6], [7, 8, 9]]], dtype=torch.float32)
  K_2 = torch.tensor([[[0, 1], [2, 3]], [[1, 2], [3, 4]]], dtype=torch.float32)
  
  conv2D_multiple(X_2, K_2)
  </code></pre>
  
  <p>The results is:</p>
  
  <pre><code>tensor([[ 56.,  72.],
          [104., 120.]])
  </code></pre>
  
  <p>The result is as expected, however, I believe my second 
  for loop inside <code>conv2D_multiple(X, K)</code> function is redundant.  My question is how to sum (element wise) 
  tensors (arrays) in the list so I omit the second for loop. </p>