TheAlgorithms-Python

Форк
0
35 строк · 857.0 Байт
1
"""
2
This script demonstrates the implementation of the Binary Step function.
3

4
It's an activation function in which the neuron is activated if the input is positive
5
or 0, else it is deactivated
6

7
It's a simple activation function which is mentioned in this wikipedia article:
8
https://en.wikipedia.org/wiki/Activation_function
9
"""
10

11
import numpy as np
12

13

14
def 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

32
if __name__ == "__main__":
33
    import doctest
34

35
    doctest.testmod()
36

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.