For simplicity, I give a (3,3) matrix below, though my matrix is of a larger dimension. My objective is, after some matrix manipulations, to select Maximum element(s) in a row and a column, and place zero all the cells except the maximum elements.
mat = {{1, 4, 5}, {1, 2, 4}, {4, 1, 2}};
one = {1, 1, 1};
colTot = one.mat;
rowTot = mat.one;
colStd = Table[matColStd[i, j] = mat[[i, j]]/colTot[[j]],
{i,3}, {j,3}]//N
rowStd = Table[matRowStd[i, j] = mat[[j, i]]/rowTot[[j]],
{j,3}, {i,3}] // N
solColMat = {{0,0.5714,0.4545}, {0,0, 0}, {0.6666,0,0}};
solRowMat ={{0,0,0.5}, {0,0,0.5714},{0.5714,0,0}};
The above Code
column-wise standardizes mat
, denoted by colStd
. Using the same matrix mat
I also introduce a row-standardization rowStd
. The standardization of the Code
works just fine.
My purpose is to create two new matrices solColMat
and solRowMat
, which respectively select maximum
element(s) from each column and from each row. Non-maximum elements are converted to zeros. The final matrices, solColMat
and solRowMat
, are given above for clarification purposes.
I would like to have your help.
Thanks.