title: Mathematical rectangle function Python
body: <p>I want to make convolution of gaussian and rectangular functions like that:</p>
  
  <pre><code>from numpy import linspace, sqrt, sin, exp, convolve, abs
  from matplotlib import pyplot as plt
  
  
  def gauss(x, x0=0, sigma=1):
      return exp(-1*(x-x0)**2/(2*sigma**2))
  
  def rect(x):
      return 1 if abs(x)&lt;=0.5 else 0
  
  x = linspace(-10, 10, 100)
  
  f1 = gauss(x, sigma=1)
  f2 = rect(x)
  fsum = convolve(f1, f2)
  
  y = linspace(-10, 10, 199)
  
  plt.plot(x, f1)
  plt.plot(x, f2)
  plt.plot(y, fsum)
  plt.show()
  </code></pre>
  
  <p>But I can't correctly describe rect function:</p>
  
  <pre><code>return 1 if abs(x)&lt;=0.5 else 0
  ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
  </code></pre>