title: Python : Runtime Warning : Overflow encountered in square, add, multiply, substract
body: <p>I'm beginning with Python so I might be asking a not so subtle question, but after quite a lot of research I couldn't resolve this error.
  I'm actually trying to solve a physics problem using the Gray-Scott model, but I'm stuck at the very end of the code :  the results are not considered as numbers and there's an overflow encountered in square, add, multiply and substract.</p>
  
  <p>Anyone here have the slightest idea of where this comes from ?</p>
  
  <p>Thanks !</p>
  
  <p>These are the initial conditions of the problem I'm trying to solve :</p>
  
  <pre><code>n = 192
  Du, Dv, F, k = 0.00016, 0.00008, 0.035, 0.065 
  dh = 5/(n-1)  
  T = 8000
  dt = .9 * dh**2 / (4*max(Du,Dv))
  nt = int(T/dt)
  
  uvinitial = numpy.load('./uvinitial.npz')
  
  Uin = uvinitial['U']
  Vin = uvinitial['V']
  </code></pre>
  
  <p>Now here are my functions :</p>
  
  <pre><code>def Nd1(U,V) :
      return - U*(V)**2 + F*(1-U)
  
  
  def Nd2(U,V) :
      return U*(V)**2 -(F+k)*V
  
  
  def gray_scott_solve(Du, Dv, dh, dt, nt, Uin, Vin, Nd1, Nd2):
  
      Uplus = Uin.copy()
      Vplus = Vin.copy()
  
      for n in range(nt):
  
          U = Uplus.copy()  
          V = Vplus.copy()
  
          Uplus[1:-1,1:-1] = ( Nd1(U[1:-1,1:-1], V[1:-1,1:-1]) + Du/(dh**2) \
                              *(U[2:,1:-1] + U[:-2,1:-1] - 4*U[1:-1,1:-1]) \
                              + U[1:-1,2:] + U[1:-1,:-2] )*dt \
                              + U[1:-1,1:-1]
  
          Uplus[:,-1] = Uplus[:,-2]    
          Uplus[-1,:] = Uplus[-2,:]
          Uplus[:,0] = Uplus[:,1]
          Uplus[0,:] = Uplus[1,:]
  
          Vplus[1:-1,1:-1] = ( Nd2(U[1:-1,1:-1], V[1:-1,1:-1]) + Du/(dh**2) \
                              *(V[2:,1:-1] + V[:-2,1:-1] - 4*V[1:-1,1:-1]) \
                              + V[1:-1,2:] + V[1:-1,:-2] )*dt \
                              + V[1:-1,1:-1]
  
          Vplus[:,-1] = Vplus[:,-2]
          Vplus[-1,:] = Vplus[-2,:]
          Vplus[:,0]= Vplus[:,1]
          Vplus[0,:]= Vplus[1,:]
  
  
      return U, V
  </code></pre>
  
  <p>I now want to print the results I'm looking for :</p>
  
  <pre><code>U, V = gray_scott_solve(Du, Dv, dh, dt, nt, Uin, Vin, Nd1, Nd2)
  
  print(U[100,::40])
  </code></pre>
  
  <p>And I finally get this error :</p>
  
  <pre><code>[ nan  nan  nan  nan  nan]
  
  C:\Users\Anto\Anaconda3\lib\site-packages\ipykernel\__main__.py:2: RuntimeWarning: overflow encountered in square from ipykernel import kernelapp as app
  C:\Users\Anto\Anaconda3\lib\site-packages\ipykernel\__main__.py:2: RuntimeWarning: overflow encountered in multiply from ipykernel import kernelapp as app
  C:\Users\Anto\Anaconda3\lib\site-packages\ipykernel\__main__.py:5: RuntimeWarning: overflow encountered in square
  C:\Users\Anto\Anaconda3\lib\site-packages\ipykernel\__main__.py:5: RuntimeWarning: overflow encountered in multiply
  C:\Users\Anto\Anaconda3\lib\site-packages\ipykernel\__main__.py:11: RuntimeWarning: invalid value encountered in add
  C:\Users\Anto\Anaconda3\lib\site-packages\ipykernel\__main__.py:11: RuntimeWarning: overflow encountered in multiply
  C:\Users\Anto\Anaconda3\lib\site-packages\ipykernel\__main__.py:11: RuntimeWarning: invalid value encountered in subtract
  C:\Users\Anto\Anaconda3\lib\site-packages\ipykernel\__main__.py:18: RuntimeWarning: invalid value encountered in add
  C:\Users\Anto\Anaconda3\lib\site-packages\ipykernel\__main__.py:18: RuntimeWarning: overflow encountered in multiply
  C:\Users\Anto\Anaconda3\lib\site-packages\ipykernel\__main__.py:18: RuntimeWarning: invalid value encountered in subtract
  </code></pre>