Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a heaviside step function exist?

Tags:

python

matlab

Is there a heaviside function in Python similar to that of MATLAB's heaviside?

I am struggling to find one.

like image 608
8765674 Avatar asked Feb 27 '13 19:02

8765674


People also ask

Is Heaviside function same as unit step function?

The Heaviside step function H(x), also called the unit step function, is a discontinuous function, whose value is zero for negative arguments x < 0 and one for positive arguments x > 0, as illustrated in Fig.

Does the limit exist in the Heaviside function?

Graph of Heaviside function H(x). The limit exists at all a > 0. No matter how close the point a is to 0, we can always approach it from both sides. The limit exists at all a < 0.


1 Answers

If you are using numpy version 1.13.0 or later, you can use numpy.heaviside:

In [61]: x Out[61]: array([-2. , -1.5, -1. , -0.5,  0. ,  0.5,  1. ,  1.5,  2. ])  In [62]: np.heaviside(x, 0.5) Out[62]: array([ 0. ,  0. ,  0. ,  0. ,  0.5,  1. ,  1. ,  1. ,  1. ]) 

With older versions of numpy you can implement it as 0.5 * (numpy.sign(x) + 1)

In [65]: 0.5 * (numpy.sign(x) + 1) Out[65]: array([ 0. ,  0. ,  0. ,  0. ,  0.5,  1. ,  1. ,  1. ,  1. ]) 
like image 54
Warren Weckesser Avatar answered Sep 19 '22 02:09

Warren Weckesser