# How to compute adjustment weights to match marginal sums of a matrix?

I have a feeling this should be very simple, but I somehow got stuck thinking about it.

I have $\it X$, which is a 15 x 18 matrix containing non-negative real values. I smoothed this matrix using a moving window smoother, which resulted in a matrix $\it Y$ of the same dimensions, but unfortunately the total sum for this new matrix changed.

My question is, how do I create a 15 x 18 matrix $\it W$ containing adjustment weights, such that the marginals sums of $\mathit{Y \cdot W}$ after smoothing agree with the corresponding row and column sums of $\it X$ prior to smoothing?

Thanks very much for your help!