I want to implement the following algorithm in Mathematica.
Get element along main diagonal of a matrix.
If the element along the main diagonal is positive, then return the positions of the elements in the corresponding column that are negative.
If the element along the main diagonal is negative, then return the positions of the elements in the corresponding column that are positive. The positions returned are the positions in the table.
If neither of the two conditions above are true, do nothing.
Here is example of what I want
Given the matrix
{{1, 1, 1}, {2, -2, 2}, {-3, 3, 3}}
the algorithm should produce
{{3, 1}, {1, 2}, {3, 2}}
In the above, the first element of each pair is the row of an off-diagonal element, the second element of the pair is its column)
I'm currently trying to do this with a For-loop, but I can't get it to work. Besides, because Mathematica is so good with lists, I'm sure that a functional solution is possible.
SortBy[.., #[[2]]&]
my result if you want. $\endgroup$