Question: Diagonal Elements =1 in Matrix

How can I assign all diagonal elements to 1 for a matrix ?

I know how to manipulate individually elements like

restart;
A := Matrix(5, 5, f);
B := map(proc (x) options operator, arrow; `if`(x = f(1, 1) or x = f(2, 2) or x = f(1, 2), 0, x) end proc, A);

but not all diagonals. I have tried i=j but no luck so far ...humm

Please Wait...