title: Dirac Delta function with Python
body: <p>I tried to plot the Dirac Delta rectangular function in Python 2.7 code such that:</p>
  <p><a href="https://i.stack.imgur.com/QALGy.png" rel="nofollow noreferrer">enter image description here</a></p>
  <pre><code>from __future__ import division
  
  import numpy as np
  import matplotlib.pyplot as plt
  
  def ddf(x,sig):
      if -(1/(2*sig))&lt;=x and x&lt;=(1/(2*sig)):
          val=sig
      else:
          val=0
      return val
  
  X=np.linspace(-5,5,1000)
  
  for sig in np.arange(1,5,0.1):
      plt.cla()
      plt.grid()
      plt.title('Dirac Delta function',size=20)
      plt.xlabel('X values',size=10)
      plt.ylabel(&quot;Dirac Delta functions' values&quot;,size=10)
      plt.ylim(0,1)
      plt.plot(X,ddf(X,sig),color='black')
      plt.pause(0.5)
  
  plt.show()
  </code></pre>
  <p>But when I ran the code it gave the error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;c:/Users/Shubhadeep/Desktop/dff.py&quot;, line 22, in &lt;module&gt;
      plt.plot(X,ddf(X,sig),color='black')
    File &quot;c:/Users/Shubhadeep/Desktop/dff.py&quot;, line 7, in ddf
      if -(1/(2*sig))&lt;=x and x&lt;=(1/(2*sig)):
  ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
  </code></pre>
  <p>Can anyone solve this?</p>