Index of the row with most non-zero elements This is a simple one: Take a matrix of integers as input, and output the index of the row with the most non-zero elements. You may assume that there will only be one row with the most non-zero elements.

Test cases:

These are 1-indexed, you may choose if you want 0 or 1-indexed.

1
0
row = 1
---
0  -1
0   0
row = 1
---
1   1   0   0   0
0   0   5   0   0
2   3   0   0   0
0   5   6   2   2
row = 4
---
0   4   1   0
0   0  -6   0
0   1   4  -3
2   0   0   8
0   0   0   0
row = 3
MATL, 6 bytes

!gs&amp;X&gt;


Input is a matrix, with ; as row separator.

Try it online! Or verify all test cases.

Explanation

!     % Transpose
g     % Logical: convert non-zeros to 1
s     % Sum of each column, or sum of row if there's a single row
&amp;X&gt;   % Arg max. Implicitly display