MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / binary_step

Function binary_step

neural_network/activation_functions/binary_step.py:14–29  ·  view source on GitHub ↗

Implements the binary step function Parameters: vector (ndarray): A vector that consists of numeric values Returns: vector (ndarray): Input vector after applying binary step function >>> vector = np.array([-1.2, 0, 2, 1.45, -3.7, 0.3]) >>> binary_step(vector)

(vector: np.ndarray)

Source from the content-addressed store, hash-verified

12
13
14def binary_step(vector: np.ndarray) -> np.ndarray:
15 """
16 Implements the binary step function
17
18 Parameters:
19 vector (ndarray): A vector that consists of numeric values
20
21 Returns:
22 vector (ndarray): Input vector after applying binary step function
23
24 >>> vector = np.array([-1.2, 0, 2, 1.45, -3.7, 0.3])
25 >>> binary_step(vector)
26 array([0, 1, 1, 1, 0, 1])
27 """
28
29 return np.where(vector >= 0, 1, 0)
30
31
32if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected