NumPy heaviside applies a step rule with an explicit value at zero
A step function distinguishes negative inputs from positive inputs, while leaving one important choice at the boundary. NumPy heaviside makes that choice explicit through its second argument. Academia Master Trader presents this English lesson for readers in Angola, using constructed values to explain the boundary, shifted thresholds and element-wise evaluation.
Three input cases define the rule
After import numpy as np, define values = np.array([-3.,0.,4.]). The call np.heaviside(values,0.5) returns [0.,0.5,1.].
A negative first input produces zero. A positive first input produces one. When the first input equals zero, the result is the second input, here one half.
The second argument is therefore not a threshold location. It supplies the output specifically at zero. Confusing these roles would change the intended calculation.
This step rule does not retain the magnitude of each input: minus three and another negative number both map to zero. Positive numbers similarly map to one, regardless of their size.

The zero convention is part of the calculation
The call np.heaviside(values,0.) returns [0.,0.,1.], while np.heaviside(values,1.) returns [0.,1.,1.].
Only the zero input changes between these examples. Negative and positive inputs keep their outputs of zero and one.
A boundary value of one half is a common convention, but it is not forced by the function. Choose and record the convention required by the mathematical definition being implemented.
Exact equality to zero matters here. A tiny positive input still produces one, and a tiny negative input produces zero. The second argument does not establish a tolerance interval around the boundary.
Shift the first input to move a threshold
To place a boundary at five, define samples = np.array([4.,5.,6.]) and evaluate np.heaviside(samples-5.,0.5). The result is [0.,0.5,1.].
Subtracting five moves the chosen boundary to zero before the step rule is applied. The second argument still determines only the output at that boundary.
This construction explains the operation without implying a decision about real observations. A numeric step is a transformation of supplied values, not a prediction, a probability or an instruction to act.
Boundary values can vary element by element
The call np.heaviside([0.,0.,0.],[0.,0.5,1.]) returns [0.,0.5,1.]. Each zero input receives its corresponding second input.
The two inputs must have shapes that broadcast to a common output shape. A scalar boundary value can be shared across a vector, as in the opening example, while a compatible array can supply separate boundary values.
The operation is element-wise. It does not sort inputs, count how often a threshold was crossed or remember an earlier value in a sequence. Those tasks require their own operations and an explicit interpretation of order.
Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the first-input transformation and the chosen value at zero when explaining a step calculation.