Question: How can I retrieve the indices of specific values in a matrix?

I have a matrix (M) and it has both 0 and 1 as entries. I want to have a sequence/list of all indices associated with the entries equal to one (the others are irrelevant to me). I can use a nested for loop with an if statement, but I find that the easy way out and not very pretty. Is there is more sophisticated way, hopefully faster way of achieving this (using sequences, attributes, select/remove)?

Example:

M:=Matrix([[1,1,0],[0,0,1],[1,0,1]]);

then the list I want is

[[1,1],[1,2],[2,3],[3,1],[3,3]]

which makes it easier afterwards to loop through the list with sequences, which is what I have to do.

Cheers,

Fred.

Please Wait...