hugodecasta - 1 year ago 131

Python Question

I'm developing a model based on neural network principals.

I have an entry layer, weights and an output layer:

`[1,2] -- [ [1,1] , [1,1] ] --> [3,3]`

My question is whether Python has a simple way (with numpy) to compute the output layers without doing loops and loops.

The current implementation is:

`for i in range(0,number_of_out_neurons):`

out_neuron_adder_toWrap = weights[i] * all_input_layer

out_neuron[i] = sum(out_neuron_adder) <-- wrapping

Answer Source

You can implement this with `numpy.dot`

```
In [1]: import numpy as np
In [2]: a
Out[2]: array([1, 2])
In [3]: b
Out[3]:
array([[1, 1],
[1, 1]])
In [4]: np.dot(a,b)
Out[4]: array([3, 3])
```

Here is more Reference about `numpy.dot`