title: How to implement step-like function in python
body: <p>I am frequently using the following construct to implement the Heaviside step function</p>
  
  <pre><code>def f(x,xm):   
     1 * (xm &gt; c)
  </code></pre>
  
  <p>I used the same to implement the CDF of the Pareto distribution.</p>
  
  <pre><code>def pareto_cum(x,xm,a):
       return (1.-(xm/x)**a) * (x &gt; xm)
  </code></pre>
  
  <p>Unfortunately this produces an error message in python 3. I don't understand why division by zero is a problem here, since always <code>xm&gt;0</code>. That is, <code>x &gt; 0</code> should be guaranteed by default. </p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  
  x=np.linspace(0,10,100000)
  def pareto_cum(x,xm,a):
       return (1.-(xm/x)**a) * (x &gt; xm)
  
  plt.plot(x,pareto_cum(x,2,3))
  __main__:2: RuntimeWarning: divide by zero encountered in true_divide
  __main__:2: RuntimeWarning: invalid value encountered in multiply
  [&lt;matplotlib.lines.Line2D object at 0x7fdf026770b8&gt;]
  </code></pre>
  
  <p>CDF of the Pareto distribution <a href="http://pareto%20distribution" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Pareto_distribution</a></p>