# Matrix Multiplication, Standard Deviant and More usefull methods

I’m trying to create a Artificial Neural Network to make a evolving AI for a simple game.

But I’m struggling with the math required by it.

I made a neural net in Python, in around 100 lines, but when I tried to port it to c# I’m already at 200 lines of code, and I haven’t even begin the back propagation algorithm (the bulk of the code in python).

For instance a simple input normalization in python takes 1 line:

``````self.input_values = (inputs - np.mean(inputs , axis=0)) / np.std(inputs , axis=0)
``````

While in C# I’ve to do it step by step:

``````float[] normalize_input(float[] inputs){
float sum = 0.0f;
for (int i = 0; i < inputs.Length; i++) {
sum += inputs *;*
``````

}
float average = sum / inputs.Length;

float[] deviations = new float[inputs.Length];

for (int i = 0; i < inputs.Length; i++) {
deviations = Mathf.Pow(inputs - average,2);
}

float sum_deviation = 0;

for (int i = 0; i < deviations.Length; i++) {
sum_deviation += deviations*;
_}*_

float variance = sum_deviation / deviations.Length;

float std = Mathf.Sqrt (variance);

for (int i = 0; i < inputs.Length; i++) {
inputs = (inputs - average)/std;
}

return inputs;
}
Is there any way to have access to this sort of math functions and matrix computation?
I know I can do it step by step like I’m doing, but it will take a lot longer, and further more, it’s very hard to debug once something is off.

You have the Mathf library which have some formulas. There’s also the default C# Math library.

Other than that, you should just define all of the helpers you need. It’s not very hard to define arbitrary-length mean methods, or matrix multiplication methods.

I’m not that experienced with Python, but if you want to write C# code that handles vectors and matrices in a similar way to, say, MATLAB or Octave, you can try http://numerics.mathdotnet.com/ - I believe the Normalize() method will then provide the single-line method you’re looking for.