title: RuntimeWarning: invalid value encountered in true_divide
body: <p>I have to make a program using NLMS method, to minimize the noise in ECG signal.   </p>
  
  <pre><code>from __future__ import division
  from numpy import *
  import numpy as np
  #import matplotlib as plt
  import matplotlib.pyplot as plt
  import os
  clear = lambda: os.system('cls')
  
  clear() 
  meu=1e-05 
  file=open('ecg.txt','r') #this file i attached at below
  data=file.readlines()
  
  x=data[:1000] 
  xx=data[1001:2001]
  N=len(x)
  NN=len(xx)
  t=np.zeros((N,1),float)
  X=np.zeros((4,1),float)
  Z=np.array([0,0,0,0],float)
  w=random.rand(4,1)
  y=np.zeros((N,1),float)
  yp=np.zeros((N,1),float)
  e=np.zeros((N,1))
  j=np.zeros((N,1),float)
  
  for n in range(len(x)):
      X[1:len(X)-1]=X[0:len(X)-2]
      X[0]=x[n]
  
      sum=0
  
      for k in range(len(X)):
          sum+=(w[k].T*X[k])
          y[n]=sum
          e[n]=subtract(X[0],y[n])
          j[n]=e[n]*e[n]
  
  for l in range(len(X)):
          w[l] = w[l]+(meu*e[n]*X[l])/((X[l]*X[l])*(X[l]*X[l])); #when division takes place it give error
  
  
  
  
  
  MSE=mean(j,1)
  plt.plot(10 * log10(MSE))
  plt.title('MSE')
  plt.show()
  
  
  #print(' output\n')
  #print(y,'\n')
  #print(' data\n')
  #print(x,'\n')
  print(w)
  #y.astype(float)
  #pp=np.int16(y)
  
  plt.plot(x)
  plt.yscale('log')
  plt.title('x')
  plt.show()
  
  plt.plot(y)
  plt.yscale('log')
  plt.title('y')
  plt.show()
  
  plt.plot(w)
  plt.yscale('log')
  plt.title('w')
  plt.show()
  
  plt.plot(e)
  #plt.yscale('log')
  plt.title('e')
  plt.show()
  
  plt.plot(e)
  plt.plot(x)
  plt.plot(y)
  plt.show()
  
  plt.plot(yp)
  plt.title('yp')
  plt.show()
  
  #plt.plot(t)
  #plt.yscale('log')
  #plt.show()
  </code></pre>
  
  <p>I keep getting this error:</p>
  
  <pre><code>Warning (from warnings module):
        w[l] = w[l]+(meu*e[n]*X[l])/((X[l]*X[l])*(X[l]*X[l]));
  RuntimeWarning: invalid value encountered in true_divide
  </code></pre>
  
  <blockquote>
    <p>Result:</p>
  </blockquote>
  
  <pre><code>&gt;&gt;w
  array([[ 0.86035037],
         [ 0.35119551],
         [ 0.40570589],
         [        nan]])
  
  &gt;&gt;X
  array([[ 0.19258605],
         [ 0.19442064],
         [ 0.19243968],
         [ 0.        ]])
  &gt;&gt;w[l]
  array([ nan])
  
  &gt;&gt;X[l]
  array([ 0.])
  </code></pre>
  
  <p>I can't figure it out, what is wrong with the code?</p>
  
  <blockquote>
    <p>ECG text file:</p>
  </blockquote>
  
  <p><a href="https://www.dropbox.com/s/vt4dizapa52g8wl/ecg.txt?dl=0" rel="nofollow">click this link to view the file</a></p>