2.55 find in which columns values that are not zero

given matrix \(\begin {pmatrix} 0 & 39 & 0\\ 55 & 100 & 0\\ 34 & 0 & 0\\ 0 & 9 & 0\\ 0 & 0 & 50 \end {pmatrix} \) find the column index which contain values \(>0\) but do it from top row to the bottom row. Hence the result should be \(\left ( \overset {1st\ \operatorname {row}}{\overbrace {2}},\overset {2nd\ \operatorname {row}}{\overbrace {1,2}},\overbrace {1},\overbrace {2},\overbrace {3}\right ) \) this is becuase on the first row, nonzero is in second column, and on the second row, nonzero is at first and second column, and on the third row, nonzero is at the first column, and so on.

Mathematica

mat={{0, 39,  0}, 
     {55,100, 0}, 
     {34,0,   0}, 
     {0, 9,   0}, 
     {0, 0,   50}}; 
Position[#,x_/;x>0]&/@mat; 
Flatten[%]
 

Out[18]= {2,1,2,1,2,3}
 

 

Matlab

A=[0  39   0 
   55 100  0 
   34 0    0 
   0  9    0 
   0  0   50]; 
[I,~]=find(A'>0) 
I'
 

2     1     2     1     2     3
 

 

Maple

A:=Matrix([[0,39,0], 
           [55,100,0], 
           [34,0,0], 
           [0,9,0], 
           [0,0,50]]): 
f:=x->`if`(not evalb(A(x[1],x[2])=0),x[2],NULL): 
f~([indices(A,indexorder)]) 
 
#Or may be better is 
map(x->convert(ArrayTools:-SearchArray(x),list),[LinearAlgebra:-Row(A,[1..-1])]); 
ListTools:-Flatten(%)
 

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