I want to calculate the average of this matrix but only classes, based on this matrix:
2 4 4 0 0
1 3 5 5 5
1 5 3 2 4
2 6 2 1 3
2 5 3 0 1
The first column indicates the number of the class that belongs to the row, the first row only indicates the number of classes, the number of objects and the number of attributes.
That is:
2 4 4 0 0 //matriz[0,0] numero de clases, matriz[0,1] numero de objetos, matriz[0,2] numero de atributos
1 3 5 5 5 //matriz[1,0] clase a la que pertenece la fila osea clase 1
1 5 3 2 4 //matriz[2,0] clase a la que pertenece la fila osea clase 1
2 6 2 1 3 //matriz[3,0] clase a la que pertenece la fila osea clase 2
2 5 3 0 1 //matriz[4,0] clase a la que pertenece la fila osea clase 2
In a nutshell I want the average of each class per column.
This is my code but it only takes the average from the entire matrix.
int x = showdata.Items.Count;
int y = showdata.Items[0].ToString().Split().Count();
matriz = new Int32[x, y];
contCol = new Int32[x];
for (int i = 0; i < matriz.GetLength(0); i++)
{
for (int j = 0; j < matriz.GetLength(1); j++)
{
matriz[i, j] = Convert.ToInt32(showdata.Items[i].ToString().Split()[j]);
}
}
label4.Text = Convert.ToString(cont);
for (int i = 0; i < y; i++)
{
for (int j = 1; j < x; j++)
{
if (i == 0)
{
contCol[cont] = matriz[j, i];
listBox2.Items.Add(contCol[cont]);
}
}
cont++;
}
int f = listBox2.Items.Count;
contCol = new Int32[f];
for (int i = 0; i < contCol.GetLength(0); i++)
contCol[i] = Convert.ToInt32(listBox2.Items[i].ToString());
cont = 0;
label4.Text = Convert.ToString(contCol[0]);
for (int i=0;i<y;i++)
{
suma = 0;
if (contCol[cont] == i)
{
if (i > 0)
{
for (int j = 0; j < x; j++)
{
if (contCol[cont] == j)
{
if (j > 0)
suma = suma + matriz[j, i];
}
}
}
promedio = (suma / (x - 1));
if (promedio != 0)
listcentroide.Items.Add(promedio);
}
}