title: Numpy calculation too slow compared to Fortran
body: <p>I used to mainly use the Fortran, but recently I started using python and Numpy for deep-learning application.</p>
  <p>But, calculating the double for-loop in python was significantly slower than the Fortran. I already knew the Fortran is originally fast in calculation, but I would like to know if there is anything wrong with my python code. This is the code I used as follows:</p>
  <pre><code>for it in range(nt):
      if it%20 == 1:
          print(it,'//',nt)
  
      itimenum4 = &quot;%.4i&quot; %(it)
      
      ppsix2[:,:]=0.; ppsiz2[:,:]=0.
      apsix2[:,:]=0.; apsiz2[:,:]=0.
      ax[:,:]=0.; az[:,:]=0.
      p3[:,:]=0.
      
      for iz in range(2,nnz+1):
          for ix in range(2,nnx+1):
  
              pdx2=(p2[ix+1,iz]-p2[ix,iz])*a1+(p2[ix+2,iz]-p2[ix-1,iz])*a2
              pdz2=(p2[ix,iz+1]-p2[ix,iz])*a1+(p2[ix,iz+2]-p2[ix,iz-1])*a2
  
              dpml0=math.log(1./R)*3.*vp[ix,iz]/(2.*dx*pml)
  
              if ix &lt;= pml:
                  dpml=dpml0*(float(pml-ix+1)/float(pml))**2
                  damp=math.exp(-dpml*dt)
                  ppsix2[ix,iz]=damp*ppsix1[ix,iz]+(damp-1.)*pdx2
  
              if ix &gt;nx+pml:
                  dpml=dpml0*(float(ix-(nx+pml))/float(pml))**2
                  damp=math.exp(-dpml*dt)
                  ppsix2[ix,iz]=damp*ppsix1[ix,iz]+(damp-1.)*pdx2
  
              if iz &gt; nz:
                  dpml=dpml0*(float(iz-(nz))/float(pml))**2
                  damp=math.exp(-dpml*dt)
                  ppsiz2[ix,iz]=damp*ppsiz1[ix,iz]+(damp-1.)*pdz2
  
              ax[ix,iz]=pdx2+ppsix2[ix,iz]
              az[ix,iz]=pdz2+ppsiz2[ix,iz]
          
      az[:,1]=az[:,2]
      az[:,0]=az[:,3]
  
      for iz in range(2,nnz+1):
          for ix in range(2,nnx+1):
              adx=a1*(ax[ix,iz]-ax[ix-1,iz])+a2*(ax[ix+1,iz]-ax[ix-2,iz])
              adz=a1*(az[ix,iz]-az[ix,iz-1])+a2*(az[ix,iz+1]-az[ix,iz-2])
  
              dpml0=math.log(1./R)*3.*vp[ix,iz]/(2.*dx*pml)
  
              if ix &lt;= pml:
                  dpml=dpml0*(float(pml-ix+1)/float(pml))**2
                  damp=math.exp(-dpml*dt)
                  apsix2[ix,iz]=damp*apsix1[ix,iz]+(damp-1.)*adx
  
              if ix &gt; nx+pml:
                  dpml=dpml0*(float(ix-(nx+pml))/float(pml))**2
                  damp=math.exp(-dpml*dt)
                  apsix2[ix,iz]=damp*apsix1[ix,iz]+(damp-1.)*adx
  
              if iz &gt; nz:
                  dpml=dpml0*(float(iz-(nz))/float(pml))**2
                  damp=math.exp(-dpml*dt)
                  apsiz2[ix,iz]=damp*apsiz1[ix,iz]+(damp-1.)*adz
  
              px2=adx+apsix2[ix,iz]
              pz2=adz+apsiz2[ix,iz]
  
              p3[ix,iz]=2.*p2[ix,iz]-p1[ix,iz]+(dt*vp[ix,iz])**2*((px2+pz2)+srcf[ix,iz]*source[it])
  
              if iz == recz:
                  mod_p[ix,it]=p3[ix,iz]
  
      p3[:,0:2]=0.
  
      p1[:,:]=p2[:,:]
      p2[:,:]=p3[:,:]
      ppsix1[:,:]=ppsix2[:,:]
      ppsiz1[:,:]=ppsiz2[:,:]
      apsix1[:,:]=apsix2[:,:]
      apsiz1[:,:]=apsiz2[:,:]
  </code></pre>
  <p>This is the conventional first-order acoustic wave equation in geophysics. Anyway, I used the Numpy array. Is there any factors that makes calculation slow?</p>
  <p>Thanks.</p>