hugodecasta hugodecasta - 1 year ago 222
Python Question

Python - cross array multiplication

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]

Simple Neural Network based on two layers and one weight layer

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

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

Here is more Reference about

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download