One Layer Perceptron Neural Network, Inputs

Asked

Viewed 43 times

-1

Hello I’m having a doubt about going through the input and data weight without using the numpy.

#AND

entrada = [[0,0],[0,1],[1,0],[1,1]]

peso = [0.0,0.0]

The way I figure it is : inada1 x weight + inada2 x weight = 0

on lp:

0 * 0.0 + 0 * 0.0 = 0.0

A loop to scroll through the list and another loop to sublists.

exemplo loop usado :
for a in range(len(entrada)):
  calc = entrada[a][0] * peso +  entrada[a][1] * peso

until then the result is desired but if there are more than 2 entries as could be the loop without needing Calc = input[a][0] * weight + input[a][1] * weight + input[a][2] * weight

Instead of specifying the position allocate directly, I try to do multiplication and adding with another multiplication.

in syntax is multiply each list and add.

1 answer

0


The easiest way to do it is by using the library numpy. To install numpy, run:

pip install numpy   # ou pip3, dependendo do seu sistema

After installation, just use:

import numpy

entrada = numpy.array([[0,0],[0,1],[1,0],[1,1]])
peso = numpy.array([0.0, 0.0])

resultado = entrada * peso.transpose()   # multiplicacao
saida = [sum(l) for l in resultado.tolist()]   #soma, usando list comprehension

Exit from the program:

[0.0, 0.0, 0.0, 0.0]

Changing the weights just to test:

peso = numpy.array([1.0, 2.0])

Output with new weights:

[0.0, 2.0, 1.0, 3.0]
  • Thanks for the help. I know numpy is very good for rna, but I am looking for a solution that is not external lib, but thanks for the reply.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.