# Finding a better way to define a matrix

I first defined a 171x171 matrix containing only zeros and then replaced 18 specific rows with nonzero entries.

The other $153$ rows will be average of $2$ of the existing $18$ rows.

Rows $2$ through $18$ are the averages of Row $1$ and every other defined row since there are $17$ other rows for Row $1$ to combine with.

Now we need to see average of Row $19$ being combined with the $18$ other rows. But the average of Row $19$ and Row $1$ has already been defined since it is also the same as the average of Row $1$ and Row $19$. So Row $19$ only needs to be combined with $16$ other rows.

When we wish to see the average of Row $36$ combined with the other defined rows,the average of Row $36$ and Row $1$,and the average of Row $36$ and Row $19$ have already been defined, so there are only $15$ possible remaining rows for Row $36$ to combine with.

This pattern continues until every row of the matrix is defined. This matrix is already well defined and there are no errors. The code works but I'm wondering if there is a better and certainly much shorter way to define this matrix with iterative functions such as Do, Array or Table. Any feedback, comments, or corrections is greatly appreciated. Thank you.

o = Array[0 &, {171, 171}]

o[[1]] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, .5, 0, 1, 1, .5, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, .5, 0, 1, 1, .5, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, .5, 0, 1, 1, .5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, .5, 0, 1,
1, .5, 1, 1, 1, 1, 1, 1, 1, 1, 1, .5, 0, 1, 1, .5, 1, 1, 1, 1, 1,
1, 1, 1, .5, 0, 1, 1, .5, 1, 1, 1, 1, 1, 1, 1, .5, 0, 1, 1, .5, 1,
1, 1, 1, 1, 1, .5, 0, 1, 1, .5, 1, 1, 1, 1, 1, .5, 0, 1, 1, .5, 1,
1, 1, 1, .5, 0, 1, 1, .5, 1, 1, 1, .5, 0, 1, 1, .5, 1, 1, .5, 0, 1,
1, .5, 1, .5, 0, .5, .5, .25, .5, 0, 0, 0, 0, 0, 1, 1, .5, 1, 1, .5,
1, .5, .5, 1}

o[[19]] = {1, .5, .5, 1, 2, 2, 1, 1, 1, 1, 1, 2, .5, 1, .5, 1, 2,
1, .5, .25, .5, 1, 1, .5, .5, .5, .5, .5, 1, .25, .5, .25, .5,
1, .5, .5, .5, 1, 1, .5, .5, .5, .5, .5, 1, .25, .5, .25, .5, 1, .5,
1, 2, 2, 1, 1, 1, 1, 1, 2, .5, 1, .5, 1, 2, 1, 2, 4, 2, 2, 2, 2, 2,
4, 1, 2, 1, 2, 4, 2, 2, 2, 2, 2, 2, 2, 4, 1, 2, 1, 2, 4, 2, 1, 1,
1, 1, 1, 2, .5, 1, .5, 1, 2, 1, 1, 1, 1, 1, 2, .5, 1, .5, 1, 2, 1,
1, 1, 1, 2, .5, 1, .5, 1, 2, 1, 1, 1, 2, .5, 1, .5, 1, 2, 1, 1,
2, .5, 1, .5, 1, 2, 1, 2, 1, 2, 1, 2, 4, 2, .5, .5, .25, .5, 1, .5,
1, .5, 1, 2, 1, .5, .5, 1, .5, 1, 2, 1, 2, 2, 1}

o[[36]] = {1, 2, .5, 1, .5, 1, 1, 1, 2, 1, 1, 1, 2, 1, .5, 1, 1, 1, 2,
1, 2, 1, 2, 2, 2, 4, 2, 2, 2, 4, 2, 1, 2, 2,
2, .5, .5, .25, .5, .5, .5, 1, .5, .5, .5, 1, .5, .25, .5, .5, .5,
1, .5, 1, 1, 1, 2, 1, 1, 1, 2, 1, .5, 1, 1, 1, .5, .5, .5, .5,
1, .5, .5, .5, 1, .5, .25, .5, .5, .5, 1, 1, 1, 2, 1, 1, 1, 2,
1, .5, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, .5, 1, 1, 1, 1, 2, 1, 1, 1,
2, 1, .5, 1, 1, 1, 2, 2, 2, 2, 4, 2, 1, 2, 2, 2, 1, 1, 1, 2, 1, .5,
1, 1, 1, 1, 1, 2, 1, .5, 1, 1, 1, 1, 2, 1, .5, 1, 1, 1, 2, 2, 1, 2,
2, 2, 1, .5, 1, 1, 1, .5, .5, .5, .5, 1, 1, 1, 1, 1, 1}

o[[52]] = {1, 1, 2, .5, .5, 1, 1, 1, 0, 2, 1, 1, 1, 1, .5, 1, 1, 1, 1,
2, .5, .5, 1, 1, 1, 0, 2, 1, 1, 1, 1, .5, 1, 1, 1, 2, 1, 1, 2, 2,
2, 0, 4, 2, 2, 2, 2, 1, 2, 2, 2, .5, .25, .5, .5, .5, 0,
1, .5, .5, .5, .5, .25, .5, .5, .5, .5, .5, .5, .5, 0,
1, .5, .5, .5, .5, .25, .5, .5, .5, 1, 1, 1, 0, 2, 1, 1, 1, 1, .5,
1, 1, 1, 1, 1, 0, 2, 1, 1, 1, 1, .5, 1, 1, 1, 1, 0, 2, 1, 1, 1,
1, .5, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 1, 2,
2, 2, 1, 1, 1, 1, .5, 1, 1, 1, 1, 1, 1, .5, 1, 1, 1, 1, 1, .5, 1, 1,
1, 1, .5, 1, 1, 1, .5, .5, .5, .5, 1, 1, 1, 1, 1, 1}

o[[67]] = {1, .5, 2, 1, .5, 1, 1, .5, 2, .5, 1, .5, 2, 1, .5, 1, .5,
1, .5, 1, .5, .25, .5, .5, .25, 1, .25, .5, .25,
1, .5, .25, .5, .25, .5, 2, 2, 1, 2, 2, 1, 4, 1, 2, 1, 4, 2, 1, 2,
1, 2, 1, .5, 1, 1, .5, 2, .5, 1, .5, 2, 1, .5, 1, .5,
1, .5, .5, .5, .25, 1, .25, .5, .25, 1, .5, .25, .5, .25, .5, 1,
1, .5, 2, .5, 1, .5, 2, 1, .5, 1, .5, 1, 1, .5, 2, .5, 1, .5, 2,
1, .5, 1, .5, 1, .5, 1, .25, .5, .25, 1, .5, .25, .5, .25, .5, 2, 1,
2, 1, 4, 2, 1, 2, 1, 2, .5, .5, .25, 1, .5, .25, .5, .25, .5,
1, .5, 2, 1, .5, 1, .5, 1, .5, 1, .5, .25, .5, .25, .5, 2, 2, 1, 2,
1, 2, 1, .5, 1, .5, 1, .5, .5, .25, .5, 1, .5, 1, .5, .5, 1}

o[[81]] = {1, .5, .5, 1, 2, .5, 1, 1, 2, 2, 1, 1, 1, 1, 2, 1, .5,
1, .5, .25, .5, 1, .25, .5, .5, 1, 1, .5, .5, .5, .5,
1, .5, .25, .5, .5, .5, 1, .25, .5, .5, 1, 1, .5, .5, .5, .5,
1, .5, .25, .5, 1, 2, .5, 1, 1, 2, 2, 1, 1, 1, 1, 2, 1, .5, 1, 2, 1,
2, 2, 4, 4, 2, 2, 2, 2, 4, 2, 1, 2, .5, .5, .5, 1,
1, .5, .5, .5, .5, 1, .5, .25, .5, 1, 1, 2, 2, 1, 1, 1, 1, 2, 1, .5,
1, 1, 2, 2, 1, 1, 1, 1, 2, 1, .5, 1, 2, 4, 2, 2, 2, 2, 4, 2, 1, 2,
2, 2, 2, 2, 2, 4, 2, 1, 2, 1, 1, 1, 1, 2, 1, .5, 1, 1, 1, 1, 2,
1, .5, 1, 1, 1, 2, 1, .5, 1, 1, 2, 1, .5, 1, 2, 2, 1, 2, 1, .5,
1, .5, .5, 1}

o[[94]] = {2, 2, 2, 2, 2, 4, 2, 1, 2, 1, 1, 1, 4, 0, 2, 4, 4, 1, 1, 1,
1, 1, 2, 1, .5, 1, .5, .5, .5, 2, 0, 1, 2, 2, .5, 1, 1, 1, 2,
1, .5, 1, .5, .5, .5, 2, 0, 1, 2, 2, .5, 1, 1, 2, 1, .5,
1, .5, .5, .5, 2, 0, 1, 2, 2, .5, 1, 2, 1, .5, 1, .5, .5, .5, 2, 0,
1, 2, 2, .5, 2, 2, 1, 2, 1, 1, 1, 4, 0, 2, 4, 4, 1, 1, .5,
1, .5, .5, .5, 2, 0, 1, 2, 2, .5, .5, .5, .25, .25, .25, 1, 0, .5,
1, 1, .25, 1, .5, .5, .5, 2, 0, 1, 2, 2, .5, .5, .25, .25, 1, 0, .5,
1, 1, .25, .5, .25, 1, 0, .5, 1, 1, .25, .5, 1, 0, .5, 1, 1, .25,
2, 0, 2, 4, 4, 1, 0, 0, 0, 0, 0, 1, 2, 2, .5, 2, 4, 1, 2, 1, .5}

o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, 1, 1, 0, .5, 1, 0,
0, 0, .5, .5, 1}

o[[144]] = {1, .5, 1, 1, 2, 1, .5, .5, 1, .5, 2, 1, 1, .5, 1,
2, .5, .5, .5, .5, .5, 1, .5, .25, .25, .5, .25, 1, .5, .5, .25, .5,
1, .25, .25, 1, 1, 2, 1, .5, .5, 1, .5, 2, 1, 1, .5, 1, 2, .5, .5,
1, 2, 1, .5, .5, 1, .5, 2, 1, 1, .5, 1, 2, .5, .5, 2, 2, 1, 1, 2, 1,
4, 2, 2, 1, 2, 4, 1, 1, 1, .5, .5, 1, .5, 2, 1, 1, .5, 1,
2, .5, .5, .5, .25, .5, .25, 1, .5, .5, .25, .5,
1, .25, .25, .5, .5, .25, 1, .5, .5, .25, .5, 1, .25, .25, 1, .5, 2,
1, 1, .5, 1, 2, .5, .5, .5, 1, .5, .5, .25, .5, 1, .25, .25, 2, 2,
2, 1, 2, 4, 1, 1, 1, 1, .5, 1, 2, .5, .5, 1, .5, 1,
2, .5, .5, .5, .5, 1, .25, .25, 1, 2, .5, .5, 2, 1, 1, .5, .25, .5}

o[[151]] = {1, 2, 1, 1, 1, 2, .5, 1, .5, 2, 1, 2, 1, 1, 1, 1, .5, 1,
2, 2, 2, 2, 4, 1, 2, 1, 4, 2, 4, 2, 2, 2, 2, 1, 2, 1, 1, 1, 2, .5,
1, .5, 2, 1, 2, 1, 1, 1, 1, .5, 1, 1, 1, 2, .5, 1, .5, 2, 1, 2, 1,
1, 1, 1, .5, 1, 1, 2, .5, 1, .5, 2, 1, 2, 1, 1, 1, 1, .5, 1, 2, 1,
2, 1, 4, 2, 4, 2, 2, 2, 2, 1, 2, .5, .5, .25, 1, .5,
1, .5, .5, .5, .5, .25, .5, 1, .5, 2, 1, 2, 1, 1, 1, 1, .5, 1, .5,
1, .5, 1, .5, .5, .5, .5, .25, .5, 2, 2, 4, 2, 2, 2, 2, 1, 2, 1, 2,
1, 1, 1, 1, .5, 1, 2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 1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, .5, 0, 1,
1, 2, 1, .5, 0, 1, 2, 1, .5, 0, 2, 2, 1, 0, 1, .5, 0, .5, 0, 0}

o[[166]] = {1, 1, 1, 1, 1, 1, .5, 1, 1, 1, 2, 1, 1, 2, 1, .5, 1, .5,
1, 1, 1, 1, 1, .5, 1, 1, 1, 2, 1, 1, 2, 1, .5, 1, .5, 1, 1, 1,
1, .5, 1, 1, 1, 2, 1, 1, 2, 1, .5, 1, .5, 1, 1, 1, .5, 1, 1, 1, 2,
1, 1, 2, 1, .5, 1, .5, 1, 1, .5, 1, 1, 1, 2, 1, 1, 2, 1, .5, 1, .5,
1, .5, 1, 1, 1, 2, 1, 1, 2, 1, .5, 1, .5, .5, .5, .5, .5, 1, .5, .5,
1, .5, .25, .5, .25, 1, 1, 1, 2, 1, 1, 2, 1, .5, 1, .5, 1, 1, 2, 1,
1, 2, 1, .5, 1, .5, 1, 2, 1, 1, 2, 1, .5, 1, .5, 2, 2, 2, 4, 2, 1,
2, 1, 1, 1, 2, 1, .5, 1, .5, 1, 2, 1, .5, 1, .5, 2, 2, 1, 2, 1,
1, .5, 1, .5, .5, 1, .25, 1, .5, .5}

o[[169]] = {1, .5, .5, .5, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, .5,
2, .5, .25, .25, .5, 1, .5, .5, .5, .5, .5, .5, 1, .5, .5, .5, .25,
1, .5, .25, .5, 1, .5, .5, .5, .5, .5, .5, 1, .5, .5, .5, .25,
1, .5, .5, 1, .5, .5, .5, .5, .5, .5, 1, .5, .5, .5, .25, 1, 1, 2,
1, 1, 1, 1, 1, 1, 2, 1, 1, 1, .5, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2,
2, 1, 4, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, .5, 2, 1, 1, 1, 1, 1, 2, 1,
1, 1, .5, 2, 1, 1, 1, 1, 2, 1, 1, 1, .5, 2, 1, 1, 1, 2, 1, 1, 1, .5,
2, 1, 1, 2, 1, 1, 1, .5, 2, 1, 2, 1, 1, 1, .5, 2, 2, 2, 2, 2, 1, 4,
1, 1, 1, .5, 2, 1, 1, .5, 2, 1, .5, 2, .5, 1, 2}

o[[171]] = {1, .5, 1, 1, 1, 1, 2, .5, 1, 1, 1, 1, 1, 1, 2, 2, .5,
1, .5, .5, .5, .5, .5, 1, .25, .5, .5, .5, .5, .5, .5, 1,
1, .25, .5, 1, 1, 1, 1, 2, .5, 1, 1, 1, 1, 1, 1, 2, 2, .5, 1, 1, 1,
1, 2, .5, 1, 1, 1, 1, 1, 1, 2, 2, .5, 1, 1, 1, 2, .5, 1, 1, 1, 1, 1,
1, 2, 2, .5, 1, 1, 2, .5, 1, 1, 1, 1, 1, 1, 2, 2, .5, 1, 2, 1, 2,
2, 2, 2, 2, 2, 4, 4, 1, 2, .5, .5, .5, .5, .5, .5, .5, 1,
1, .25, .5, 1, 1, 1, 1, 1, 1, 2, 2, .5, 1, 1, 1, 1, 1, 1, 2, 2, .5,
1, 1, 1, 1, 1, 2, 2, .5, 1, 1, 1, 1, 2, 2, .5, 1, 1, 1, 2, 2, .5, 1,
1, 2, 2, .5, 1, 2, 4, 1, 2, 2, 1, 2, .5, .5, 1}

o[[2]] = (o[[1]] + o[[19]])/2
o[[3]] = (o[[1]] + o[[36]])/2
o[[4]] = (o[[1]] + o[[52]])/2
o[[5]] = (o[[1]] + o[[67]])/2
o[[6]] = (o[[1]] + o[[81]])/2
o[[7]] = (o[[1]] + o[[94]])/2
o[[8]] = (o[[1]] + o[[106]])/2
o[[9]] = (o[[1]] + o[[117]])/2
o[[10]] = (o[[1]] + o[[127]])/2
o[[11]] = (o[[1]] + o[[136]])/2
o[[12]] = (o[[1]] + o[[144]])/2
o[[13]] = (o[[1]] + o[[151]])/2
o[[14]] = (o[[1]] + o[[157]])/2
o[[15]] = (o[[1]] + o[[162]])/2
o[[16]] = (o[[1]] + o[[166]])/2
o[[17]] = (o[[1]] + o[[169]])/2
o[[18]] = (o[[1]] + o[[171]])/2

o[[20]] = (o[[19]] + o[[36]])/2
o[[21]] = (o[[19]] + o[[52]])/2
o[[22]] = (o[[19]] + o[[67]])/2
o[[23]] = (o[[19]] + o[[81]])/2
o[[24]] = (o[[19]] + o[[94]])/2
o[[25]] = (o[[19]] + o[[106]])/2
o[[26]] = (o[[19]] + o[[117]])/2
o[[27]] = (o[[19]] + o[[127]])/2
o[[28]] = (o[[19]] + o[[136]])/2
o[[29]] = (o[[19]] + o[[144]])/2
o[[30]] = (o[[19]] + o[[151]])/2
o[[31]] = (o[[19]] + o[[157]])/2
o[[32]] = (o[[19]] + o[[162]])/2
o[[33]] = (o[[19]] + o[[166]])/2
o[[34]] = (o[[19]] + o[[169]])/2
o[[35]] = (o[[19]] + o[[171]])/2

o[[37]] = (o[[36]] + o[[52]])/2
o[[38]] = (o[[36]] + o[[67]])/2
o[[39]] = (o[[36]] + o[[81]])/2
o[[40]] = (o[[36]] + o[[94]])/2
o[[41]] = (o[[36]] + o[[106]])/2
o[[42]] = (o[[36]] + o[[117]])/2
o[[43]] = (o[[36]] + o[[127]])/2
o[[44]] = (o[[36]] + o[[136]])/2
o[[45]] = (o[[36]] + o[[144]])/2
o[[46]] = (o[[36]] + o[[151]])/2
o[[47]] = (o[[36]] + o[[157]])/2
o[[48]] = (o[[36]] + o[[162]])/2
o[[49]] = (o[[36]] + o[[166]])/2
o[[50]] = (o[[36]] + o[[169]])/2
o[[51]] = (o[[36]] + o[[171]])/2

o[[53]] = (o[[52]] + o[[67]])/2
o[[54]] = (o[[52]] + o[[81]])/2
o[[55]] = (o[[52]] + o[[94]])/2
o[[56]] = (o[[52]] + o[[106]])/2
o[[57]] = (o[[52]] + o[[117]])/2
o[[58]] = (o[[52]] + o[[127]])/2
o[[59]] = (o[[52]] + o[[136]])/2
o[[60]] = (o[[52]] + o[[144]])/2
o[[61]] = (o[[52]] + o[[151]])/2
o[[62]] = (o[[52]] + o[[157]])/2
o[[63]] = (o[[52]] + o[[162]])/2
o[[64]] = (o[[52]] + o[[166]])/2
o[[65]] = (o[[52]] + o[[169]])/2
o[[66]] = (o[[52]] + o[[171]])/2

o[[68]] = (o[[67]] + o[[81]])/2
o[[69]] = (o[[67]] + o[[94]])/2
o[[70]] = (o[[67]] + o[[106]])/2
o[[71]] = (o[[67]] + o[[117]])/2
o[[72]] = (o[[67]] + o[[127]])/2
o[[73]] = (o[[67]] + o[[136]])/2
o[[74]] = (o[[67]] + o[[144]])/2
o[[75]] = (o[[67]] + o[[151]])/2
o[[76]] = (o[[67]] + o[[157]])/2
o[[77]] = (o[[67]] + o[[162]])/2
o[[78]] = (o[[67]] + o[[166]])/2
o[[79]] = (o[[67]] + o[[169]])/2
o[[80]] = (o[[67]] + o[[171]])/2

o[[82]] = (o[[81]] + o[[94]])/2
o[[83]] = (o[[81]] + o[[106]])/2
o[[84]] = (o[[81]] + o[[117]])/2
o[[85]] = (o[[81]] + o[[127]])/2
o[[86]] = (o[[81]] + o[[136]])/2
o[[87]] = (o[[81]] + o[[144]])/2
o[[88]] = (o[[81]] + o[[151]])/2
o[[89]] = (o[[81]] + o[[157]])/2
o[[90]] = (o[[81]] + o[[162]])/2
o[[91]] = (o[[81]] + o[[166]])/2
o[[92]] = (o[[81]] + o[[169]])/2
o[[93]] = (o[[81]] + o[[171]])/2

o[[95]] = (o[[94]] + o[[106]])/2
o[[96]] = (o[[94]] + o[[117]])/2
o[[97]] = (o[[94]] + o[[127]])/2
o[[98]] = (o[[94]] + o[[136]])/2
o[[99]] = (o[[94]] + o[[144]])/2
o[[100]] = (o[[94]] + o[[151]])/2
o[[101]] = (o[[94]] + o[[157]])/2
o[[102]] = (o[[94]] + o[[162]])/2
o[[103]] = (o[[94]] + o[[166]])/2
o[[104]] = (o[[94]] + o[[169]])/2
o[[105]] = (o[[94]] + o[[171]])/2

o[[107]] = (o[[106]] + o[[117]])/2
o[[108]] = (o[[106]] + o[[127]])/2
o[[109]] = (o[[106]] + o[[136]])/2
o[[110]] = (o[[106]] + o[[144]])/2
o[[111]] = (o[[106]] + o[[151]])/2
o[[112]] = (o[[106]] + o[[157]])/2
o[[113]] = (o[[106]] + o[[162]])/2
o[[114]] = (o[[106]] + o[[166]])/2
o[[115]] = (o[[106]] + o[[169]])/2
o[[116]] = (o[[106]] + o[[171]])/2

o[[118]] = (o[[117]] + o[[127]])/2
o[[119]] = (o[[117]] + o[[136]])/2
o[[120]] = (o[[117]] + o[[144]])/2
o[[121]] = (o[[117]] + o[[151]])/2
o[[122]] = (o[[117]] + o[[157]])/2
o[[123]] = (o[[117]] + o[[162]])/2
o[[124]] = (o[[117]] + o[[166]])/2
o[[125]] = (o[[117]] + o[[169]])/2
o[[126]] = (o[[117]] + o[[171]])/2

o[[128]] = (o[[127]] + o[[136]])/2
o[[129]] = (o[[127]] + o[[144]])/2
o[[130]] = (o[[127]] + o[[151]])/2
o[[131]] = (o[[127]] + o[[157]])/2
o[[132]] = (o[[127]] + o[[162]])/2
o[[133]] = (o[[127]] + o[[166]])/2
o[[134]] = (o[[127]] + o[[169]])/2
o[[135]] = (o[[127]] + o[[171]])/2

o[[137]] = (o[[136]] + o[[144]])/2
o[[138]] = (o[[136]] + o[[151]])/2
o[[139]] = (o[[136]] + o[[157]])/2
o[[140]] = (o[[136]] + o[[162]])/2
o[[141]] = (o[[136]] + o[[166]])/2
o[[142]] = (o[[136]] + o[[169]])/2
o[[143]] = (o[[136]] + o[[171]])/2

o[[145]] = (o[[144]] + o[[151]])/2
o[[146]] = (o[[144]] + o[[157]])/2
o[[147]] = (o[[144]] + o[[162]])/2
o[[148]] = (o[[144]] + o[[166]])/2
o[[149]] = (o[[144]] + o[[169]])/2
o[[150]] = (o[[144]] + o[[171]])/2

o[[152]] = (o[[151]] + o[[157]])/2
o[[153]] = (o[[151]] + o[[162]])/2
o[[154]] = (o[[151]] + o[[166]])/2
o[[155]] = (o[[151]] + o[[169]])/2
o[[156]] = (o[[151]] + o[[171]])/2

o[[158]] = (o[[157]] + o[[162]])/2
o[[159]] = (o[[157]] + o[[166]])/2
o[[160]] = (o[[157]] + o[[169]])/2
o[[161]] = (o[[157]] + o[[171]])/2

o[[163]] = (o[[162]] + o[[166]])/2
o[[164]] = (o[[162]] + o[[169]])/2
o[[165]] = (o[[162]] + o[[171]])/2

o[[167]] = (o[[166]] + o[[169]])/2
o[[168]] = (o[[166]] + o[[171]])/2

o[[170]] = (o[[169]] + o[[171]])/2

o

-
Why not show this on 5x5 matrix? – Kuba Apr 2 '14 at 20:35
the pattern for the initially populated rows : #1 (39 - #1)/2 - 18 & /@ Range[18] .. – george2079 Apr 2 '14 at 20:42
@Kuba i didnt think anyone would understand a small example so i just put what i was actually working on. im obviously new here. sorry. – jude4a Apr 3 '14 at 1:39

Another approach, maybe a little easier to understand:

Construct an array of only the initially defined rows:

 initial = o[[#1 (39 - #1)/2 - 18]] & /@ Range[18]  ;


this table procedure makes use of the fact that your 'initial' rows are also the "average" of the row with itself..:

 Transpose@
Table[ Flatten@ Table[ (initial[[j, k]] + initial[[i, k]])/2,
{i, 18}, {j, i, 18}] ,
{k, 171}] == o


True

Here is a smaller example to see what this looks like:

    n0 = 3
(initial =  Table[ A[i, j] , {i, n0}, {j, n0 (1 + n0)/2}])//MatrixForm


    Transpose@
Table[ Flatten@Table[
(initial[[j, k]] + initial[[i, k]])/2,
{i, n0}, {j, i, n0}], {k, n0 (1 + n0)/2}] // MatrixForm


Incedentally that little formula comes from here:

 FindSequenceFunction[{1, 19, 36, 52, 67}]


1/2 (-36 + 39 #1 - #1^2) &

-

I'm assuming here that the OP's code have been evaluated so we can test if the following works.

Thanks to george2079 this is the initially populated rows indices list.

start = #1 (39 - #1)/2 - 18 & /@ Range[18];

{1, 19, 36, 52, 67, 81, 94, 106, 117, 127, 136, 144, 151, 157, 162, 166, 169, 171}


I'm assuming we have rows referring to those indices somewhere in a spearate array. Here I'm just taking o[[start]] from your code.

ClearAll[g]
g = ConstantArray[0, {171, 171}];
g[[start]] = o[[start]];


As you can see, everything else is quite short. Mostly thanks to the sorted list that Subsets is giving us.

MapThread[
(g[[#]] = Mean[g[[#2]]]) &,
{Complement[Range[171], start],
Subsets[start, {2}]}
];

g == o

True

-
I really have no idea how to interpret this code. I'm obviously new to Mathematica and the stack exchanges. I'm really looking for a new way to define the new matrix such that the old definition is nearly obsolete. I wanted to keep the 18 defined rows and build it from the ground up in a new program and just forget about using the old code. My code works, it does everything I want it to, but I'm just looking for guidance to make it better. I'll try to find a way to interpret and utilize this code somehow. Thank you for your feedback. – jude4a Apr 3 '14 at 1:43
@jude4a Try to parse this code, if you face specific problems, feel free to ask. – Kuba Apr 3 '14 at 7:19
What is "start" and what is it supposed to do? Is it a variable or possibly a function? How does the array containing the row indices relate to it? Do we know what the code for the seperate array containing rows referring to the indices looks like? What exactly is the MapThread function doing with its argument? – jude4a Apr 3 '14 at 12:29
@jude4a start is in the very first line of code... {1, 19, 36, 52, ... it's a list with initial positions which you should have given us but you didn't. About MapThread, take a look here or here – Kuba Apr 3 '14 at 12:44

Another version using Subsets. I assume that the initially defined rows are stored in x, so:

x = o[[{1, 19, 36, 52, 67, 81, 94, 106, 117, 127, 136, 144, 151, 157, 162, 166, 169, 171}]];


Then the full matrix is constructed with:

o2 = Mean[x[[#]]] & /@ SortBy[Subsets[Range[18], {1, 2}], First];

o2 == o
(* True *)

-