Trusted answers to developer questions

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

In NumPy, the **heaviside()**** function** is used to compute the Heaviside step function of an input array passed to it.

The mathematical representation of the Heavyside step function, along with the rules for calculating it, is defined as follows:

Note:The$H$ notation is used here to represent the Heavyside step function. There are also other notations like$\theta$ ,$u$ , and more.

numpy.heaviside(x1, x2, /, out=None, *, where=True)

Syntax for the heaveside() function

This function takes the following parameter values:

**x1**

: This is the input array of values. This parameter is mandatory.**x2**

: This is the input value of the function when the value of `x1`

is `0`

. This parameter is mandatory.**out**

: This is the location where the result is stored. This parameter is optional. **where**

: This is the condition over which the input is being broadcast. At a given location where this condition is `True`

, the resulting array will be set to the `ufunc`

result. Otherwise, the resulting array will retain its original value. This parameter is optional.****kwargs**

: These are other keyword arguments. This is an optional parameter.It returns an array containing the Heaviside step function on the input array.

import numpy as np# creating the input arrayx1 = np.array([-1.5, 0, 2.0])x2 = 0.5# implementing the heaviside() functionmyarray = np.heaviside(x1, x2)print("Input array =", x1)print("Input value =", x2)print("Output array =", myarray)

Implementing the heaviside() function

- Line 1: We import the
`numpy`

module.

- Line 4: We define the input array,
`x1`

, and assign it some values.

- Line 5: We define the input value,
`x2`

, and assign it a value of`0.5`

.

- Line 8: We implement the
`heaviside()`

function on the arrays,`x1`

and`x2`

, and assign the result to a variable`myarray`

.

- Lines 10–12: We print the input array,
`x1`

and`x2`

. We also print the output array,`myarray`

, to the console.

RELATED TAGS

function

python

numpy

communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Related Courses