Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
799 B
1
Indexable
Never
inputs = [[1,1,1],[1,1,0],[1,0,0],[0, 0, 0],[0,1,1],[0,0,1],[0,1,0]]
weights = [[0.3, 0.3, 0],
           [0.4,-0.5,1]]

weights2 = [-1, 1]

def activation(sum):
    if (sum>=0.5):
        return 1
    else:
        return 0

def first_layer(inputs, weights):
    arr = [0]*2
    for i in range(2):
        res = 0
        for j in range(3):  
            res += inputs[j] * weights[i][j]
        arr[i] = res
    return arr

def second_layer(inputs, weights):
    sum = 0
    for i in range (len(inputs)):
        sum += inputs[i] * weights[i]
    res = activation(sum)
    return res

for i in range (7):
    inputs_first_layer = first_layer(inputs[i], weights)
    print(inputs_first_layer)
    result = second_layer(inputs_first_layer, weights2)
    print(result)