averaging two rows in a matrix with mathematica

56 Views Asked by At

If I have a $500 \times 500$ matrix and I would like to replace every ($5n-1$) row with the average of $(5n-1)$ and $(5n)$. How would I be able to do this with Mathematica?

1

There are 1 best solutions below

1
On BEST ANSWER

Suppose $A$ is the matrix. Then this should work:

ReplacePart[A, Map[(# -> (A[[#]] + A[[# + 1]])/2) &, Table[5 k-1, {k, 1, 100}]]]