title: How to use Fast Fourier Transform to execute convolution of matrix?
body: <p>I need to add many big 3D arrays (with a shape of 500x500x500) together and want to speed up the process by using multiplication in the Fourier space. The problem is that I don't get the same answer when multiplying in the Fourier space compared to simply adding the matrix.</p>
  
  <p>To test it out, I wrote a minimal example trying to make it work but the answer is not what I expected. Either my math knowledge is wrong or I am not using the function correctly.</p>
  
  <p>Below is the simplest code showing what I am trying to do:</p>
  
  <pre><code>import numpy as np
  
  c = np.asarray(((1,2),(2,3)))
  d = np.asarray(((1,4),(1,5)))
  
  print("Transform")
  Nc = np.fft.rfft2(c)
  Nd = np.fft.rfft2(d)
  
  print("Inverse")
  Nnc = np.fft.irfft2(Nc)
  Nnd = np.fft.irfft2(Nd)
  
  print("Somme")
  S = np.dot(Nc, Nd)
  print(np.fft.irfft2(S))
  </code></pre>
  
  <p>When I print S, I get the result:</p>
  
  <pre><code>[[6, 28],[10,46]]
  </code></pre>
  
  <p>But from what I understood about the Fourier space, multiplication would mean addition outside of the Fourier space so I should get <code>S = c + d</code>?</p>
  
  <p>Am I doing something wrong using the FFT function or is my assumption that S should equal c plus d wrong?</p>