[Question]
  [
**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
```
  
[Answer]
# [MATL](https://github.com/lmendo/MATL), 6 bytes
```
!gs&X>
```
Input is a matrix, with `;` as row separator.
[Try it online!](https://tio.run/##y00syfn/XzG9WC3C7v//aEMFQwUDELQGU6YQppGCMULUVMEMKGAUCwA "MATL – Try It Online") Or [verify all test cases](https://tio.run/##y00syfmf8F8xvVgtwu6/S8j/aENrBYNYrmgDBV0QC8w2VDAEsRQMwAIKphCmkYIxQtRUwQwoYATWaAJSDlGqawZhGQIFdY1BekCiFhBJkOEA).
### Explanation
```
!     % Transpose
g     % Logical: convert non-zeros to 1
s     % Sum of each column, or sum of row if there's a single row
&X>   % Arg max. Implicitly display
```
[Answer]
# Mathematica, 23 bytes
```
Ordering[Count@0/@#,1]&
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~8~~ 6 bytes
```
ΣĀO}θk
```
[Try it online!](https://tio.run/##MzBNTDJM/f//3OIjDf6153Zk//8fHW2oowBEBhAUq6MQDWGaIgSMdBSM0VUApc10FIAyRrGxAA/f3S0oY4CEBlAUKyOQjSEaYoQMNJRMEZXAZQ201EAyhjFxgIA "05AB1E – Try It Online")
-2 Bytes thanks to [Erik the Outgolfer](https://codegolf.stackexchange.com/users/41024/erik-the-outgolfer)
### Explanation
```
ΣĀO}θk
Σ  }   # Sort input by following code
 Ā      # Is element not 0? (vectorized)
  O     # Sum
    θk # Get index of "largest" element
       # Implicit print
```
[Answer]
# [R](https://www.r-project.org/), 31 bytes
```
pryr::f(which.min(rowSums(!m)))
```
returns an anonymous function which takes a matrix:
```
function(m)which.min(rowSums(!m))
```
`rowSums` sums the rows, with `!m` transforming 0 to 1 and everything else to 0. `which.min` returns the 1-based index of the first row which contains the min sum (i.e., which row has the fewest zeros).
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP08jV7M8IzM5Qy83M0@jKL88uDS3WEMxV1Pzf5pGbmJJUWaFRrKGgY6Bjq6hjoGmjpGOEVAKAA "R – Try It Online")
[Answer]
## Haskell, ~~46~~ ~~42~~ 41 bytes
```
snd.minimum.(`zip`[1..]).map(filter(==0))
```
[Try it online!](https://tio.run/##LcnLCsMgEIXhV5lFFgqTQZtQuvFJRIjQSIc4Irls@vLWQjibj/984rGtObeW3FHeJFxYLiG1fLku3hIFTRKrSpzPdVfOGa2bRC7goO5cThgggfcGZ7RoAnYZHJ83bc/j1PnAf3/df18I0H4 "Haskell – Try It Online")
How it works
```
    map                    -- for each row
        (filter(==0))      -- collect the 0s
    (`zip`[1..])           -- pair with row index  (<#0s>, <index>)
  minimum                  -- find the minimum
snd                        -- extract index from pair
```
[Answer]
# C#, 69 bytes
```
using System.Linq;m=>m.IndexOf(m.OrderBy(r=>r.Count(n=>n!=0)).Last())
```
Takes a `List<int[]>` as input and returns the 0-indexed result.
[Answer]
# [Actually](https://github.com/Mego/Seriously), 9 bytes
```
0@♀cñ♂RmN
```
[Try it online!](https://tio.run/##S0wuKU3Myan8/9/A4dHMhuTDGx/NbArK9fv/P9pQx1DHAARjdaJBtCmUbaRjjCRuqmOmY6RjFAsA "Actually – Try It Online")
Explanation:
```
0@♀cñ♂RmN
0@♀c       count zeroes in each row
    ñ♂R    enumerate and reverse each row (each row becomes [count, index] pair)
       m   minimum
        N  last element (the index)
```
[Answer]
## Python 3, ~~54~~ 48 bytes
```
lambda a:a.index(min(a,key=lambda r:r.count(0)))
```
Shaved off 6 bytes. Old solution:
```
lambda a:min(range(len(a)),key=lambda i:a[i].count(0))
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 11 bytes
```
(⊢⍳⌈/)+/0≠⎕
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qKPdN7@45L/Go65Fj3o3P@rp0NfU1jd41LngUd9UkOx/BTAAKeJ61LvKUMGAC1mkbaKGgYLCofWGmiBawUATXdYQyAFhAxiGKgRiU4SQEZAyxlQFUmEGxCBpI00sFiuYwIyHG3tovRmCbwhRcmi9McQOmPkWCFdArAMA "APL (Dyalog Unicode) – Try It Online")
`0≠⎕` Boolean matrix where non-zero
`+/` sum rows
`(` apply the following tacit function to the list of sums
 `⌈/` the maximum's
 `⍳` index
 `⊢` in the argument list
`)`
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 17 bytes
```
{{∋0}ᶜ}ᵐA;.∋₎~⌋A∧
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/v7r6UUe3Qe3DbXNqH26d4GitB@Q@auqre9TT7fioY/n//9HRhjqGOgYgGKsTDaJNoWwjHWMkcVMdMx0jHaPY2P9RAA "Brachylog – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes
```
€ĀOZk
```
[Try it online!](https://tio.run/##MzBNTDJM/f//UdOaIw3@Udn//0dHG@oY6hiAYKxONIg2hbKNdIyRxE11zHSMdIxiYwE "05AB1E – Try It Online")
0-indexed.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
TL$€M
```
[Try it online!](https://tio.run/##y0rNyan8/z/ER@VR0xrf////R0cb6hjqGIBgrE40iDaFso10jJHETXXMdIx0jGJjAQ "Jelly – Try It Online")
1-indexed.
So many 5-byte versions...
`TL$€M`, `T€L€M`, `TJ$€M`, `T€J€M`, `¬¬Ṣ€M`, `ṠAṢ€M`, `ṠAS€M`, `AṠṢ€M`, `AṠS€M`, `¬ċ€0M`, ...
[Answer]
# Haskell - ~~69~~ 68 Bytes
*Saved one byte thanks to Siracusa!*
Rows are zero indexed
```
g=filter
m y=head$g((==maximum y).(y!!))[0..]
f=m.map(length.g(0/=))
```
## Usage
```
f [[1,1,0,0,0],[2,3,0,0,0],[0,5,6,2,2],[1,1,1,1,1]]
```
[Try it online!](https://tio.run/##bY1BDoMgEEX3noImLiAZKWg13XASwoJERFKwRm3i7WmxLJq2mc3Pe/l/Rr3ejPcxWjE4v5mlCGhfxWh0X1qMhQh6d@GRIKF4X08nQiSjVBWDCDToGXsz2W2kFrOzICQG7SYkUH8vEJoXN22oRAOSkiuQTKkvyqA6BPwqDhxYureHNucamg/eQgc11H@GL6mfu1WXI3/hqjlWEr9mf/yPTw)
[Answer]
## Clojure, 64 bytes
This one works also with negative numbers in the input, luckily the same length as the original:
```
#(nth(sort-by(fn[i](count(filter #{0}(% i))))(range(count %)))0)
```
Original:
```
#(last(sort-by(fn[i](count(filter pos?(% i))))(range(count %))))
```
[Answer]
# q/kdb+, ~~25~~ ~~17~~ 16 bytes
**Solution:**
```
(*)(<)sum(+)0=/:
```
**Example:**
```
q)(*)(<)sum(+)0=/:enlist(1;0)
0
q)(*)(<)sum(+)0=/:(0 -1;0 0)
0
q)(*)(<)sum(+)0=/:(1 1 0 0 0;0 0 5 0 0;2 3 0 0 0;0 5 6 2 2)
3
q)(*)(<)sum(+)0=/:(0 4 1 0;0 0 -6 0;0 1 4 -3;2 0 0 8;0 0 0 0)
2
```
**Explanation:**
```
first iasc sum flip 0=/:  / ungolfed
                      /:  / each right, apply a function to each item to the right
                    0=    / returns boolean 1b or 0b if item in each list is equal to zero
               flip       / flip (rotate) the output
           sum            / sum these up
      iasc                / return indices if we were to sort ascending
first                     / take the first one
```
**Notes:**
~~The problem is fairly straightforward, this solution feels overly complicated.~~ As soon as I hit submit I realised the error of my ways.
**Bonus:**
Here's a k solution that weights in at ~~16~~ ~~10~~ 9 bytes - almost exactly the same but 7 bytes shorter due to the fact we don't need brackets when using the k built-ins, and as a result some become shorter than the q keywords (e.g. `+/` for `sum` (would be `(+/)` in q)).
```
*<+/+0=/:
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 11 bytes
```
{0fe=_:e<#}
```
[Try it online!](https://tio.run/##S85KzP1fWPe/2iAt1TbeKtVGufZ/XWpKrPX/6GhDBUMFAxCMVYgG0aZQtpGCMZK4qYKZgpGCUWwsAA "CJam – Try It Online")
-2 thanks to [Challenger5](https://codegolf.stackexchange.com/users/61384/challenger5).
[Answer]
# [Python 2](https://docs.python.org/2/), 62 bytes
```
lambda m:max(range(len(m)),key=lambda n:len(filter(abs,m[n])))
```
[Try it online!](https://tio.run/##LclBCoAgEEDRq7ScAYNqGXQSczGRluRMYi7y9FbQ6sP7seT9lKG6aa6BeFmp4ZHphkSyWQhWgBHVYcv0bxk/dD5km4CWS7EWg4g1Ji@5caB1p9reqDedMVgf "Python 2 – Try It Online")
[Answer]
# [PHP](https://php.net/), 58 bytes
0-Indexed
```
<?=array_search(max($a=array_map(array_filter,$_GET)),$a);
```
[Try it online!](https://tio.run/##K8go@G9jX5BRwKUS7@4aYhsdbahjqGMAgrE6XNEghimMY6RjjCxjqmOmY6RjFBtrzWVvBzTENrGoKLEyvjg1sSg5QyM3sUJDJREqlptYoAFhpWXmlKQW6YAt09TUUUnUtP7/HwA "PHP – Try It Online")
[Answer]
# [V](https://github.com/DJMcMayhem/V), 18 bytes
```
òø0
jòÚDuu/"
dGØ¾
```
[Try it online!](https://tio.run/##K/v///CmwzsMuLKA1CyX0lJ9ISWuFPfDMw7t@//fQEFBwQSIDYHYgAvEA2JdMzjPECKva8xlBJEDYwuYSggGAA "V – Try It Online")
Unlike most V answers, this is 0-indexed.
```
00000000: f2f8 300a 6af2 da44 7575 2f12 220a 6447  ..0.j..Duu/.".dG
00000010: d8be                                     ..
```
Not bad for a language with no numeric support! `;P`
I also have discovered that the uppercase variant of the *count* command, that is `Ø`, is horribly broken.
[Answer]
# [Python 3](https://docs.python.org/3/), 92 bytes
```
def f(x):
    for e in x:
        e.sort()
    y=x[:]
    y.sort()
    return x.index(y[-1])
```
First sort each row such that the entrys are `[0,0,..,0,x,x,x]` then sort the whole matrix, so that the last entry in `y` is the row we are looking for. 
The copy `y=x[:]` is necessary, since `.sort()` works inplace, hence we don't know the original index after sorting. 
I appreciate any help how to golf this solution further. Most bytes are lost because of the whitespaces in each line. The code itself is only 68 bytes long.
[Try it online!](https://tio.run/##K6gsycjPM/7/PyU1TSFNo0LTiksBCNLyixRSFTLzFCogfBBI1SvOLyrR0AQLVNpWRFvFQpjI4kWpJaVFQG16mXkpqRUaldG6hrGa//8DAA "Python 3 – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), ~~64 55 52~~ 48 bytes
* **Thanks to @Rod for shaving 9 bytes!!**: count `0`s and use `min()` instead of `max()`
* @Rod saved yet another 3 bytes: use `input()` instead of `def`
* **@ovs saved 4 bytes**: use of `lambda` and hash-map
```
lambda x:x.index(min(x,key=lambda n:n.count(0)))
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUaHCqkIvMy8ltUIjNzNPo0InO7XSFiqVZ5Wnl5xfmleiYaCpqfm/oCgzr0QhTSMzr6C0RAMoEB1tqKOgoGCAQhjE6kQjREyRhY1AHGPsqnXBKs1g4kaxsQA "Python 2 – Try It Online")
[Answer]
# JavaScript (ES6), 62 bytes
0-indexed. Takes a 2D array as input.
```
a=>(a=a.map(x=>x.filter(y=>y).length)).indexOf(Math.max(...a))
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
ċ0$ÞḢi@
```
[Try it online!](https://tio.run/##y0rNyan8//9It4HK4XkPdyzKdPj//390tIGOQawOkDQEkoZAMhYA "Jelly – Try It Online")
```
ċ0$ÞḢi@  Main link
   Þ     Sort by
ċ0$              the number of occurences of 0
    Ḣ    Take the first element
     i@  Index in the original array
```
[Answer]
# Pyth, 6 bytes
```
xQh/D0
```
[Demonstration](https://pyth.herokuapp.com/?code=xQh%2FD0&input=%5B%5B0%2C+4%2C+1%2C+0%5D%2C+%5B0%2C+0%2C+-6%2C+0%5D%2C+%5B0%2C+1%2C+4%2C+-3%5D%2C+%5B2%2C+0%2C+0%2C+8%5D%2C+%5B0%2C+0%2C+0%2C+0%5D%5D&debug=0)
Instead of finding the row with the most non-zero elements, I find the row with the least zero elements.
`/D0`: Order (`D`) by count (`/`) of zeros (`0`). Implicitly applied to `Q`, the input.
`h`: Take the first, and minimum, element.
`xQ`: Find the index (`x`) in the input (`Q`) of that element.
[Answer]
# [Retina](https://github.com/m-ender/retina), 46 bytes
```
%M`\b0
m`(?<=(¶.+)*)$
;$#1
O#`.+
!`(?<=^.+;).+
```
[Try it online!](https://tio.run/##K0otycxL/P9f1TchJsmAKzdBw97GVuPQNj1tTS1NFS5rFWVDLn/lBD1tLkWwVJyetrWmnvb//wYKCgomQGwIxAZcIB4Q65rBeYYQeV1jLiOIHBhbwFRCMAA "Retina – Try It Online")
0-indexed. Works with positive and negative integers (and 0). Assumes no leading zeros.
[Answer]
# [J](http://jsoftware.com/), 16 bytes
```
0{[:/:@:+/@|:0=]
```
[Try it online!](https://tio.run/##y/r/P83WyqA62krfysFKW9@hxsrANvZ/SWpxiYKtlYKpgomCioIBkDQEkiAYbwamDIFC8cYKRmCOBVTOgCs1OSNfAaQZwkoDs/8DAA "J – Try It Online")
[Answer]
# Java 8, 145 bytes
```
import java.util.*;m->{int t=0,s=0,i=0,r=0;for(;i<m.size();i++){List l=(List)m.get(i);for(;l.remove(0L););s=l.size();if(s>t){t=s;r=i;}}return r;}
```
Ugly, but it works..
**Explanation:**
[Try it here.](https://tio.run/##vVPRboIwFH3nK@5jOweCbr50mOzdmSU@LnuoUFwdFNJeXBzh21lBtphFkyUTGy43nJZzz2lvt3zH3bwQahu/NzIrco2wtZhXoky9GwYA4zE8cwvnCeCbgPUehRvlpULHiVJuDDxxqSoHQCoUOuGRgGX72QEQkYU0CBllFqrBvuxjkKOMYAkKwiZz51W7EkP/1tiQNnTosyTXhMmHzDPyUxDK5GhEq44sDTtSmnkbgUTSw9LU0yLLd4L4C8ooM2H682dCzBxphaFhOpSsrrXAUivQrG7YQVJRrlMrqVe2y2UMmfVFVqil2ry8AqcHU6u9QZF5eYleYacwVUR5EVHiAx615vtWGaFVxeP4NBhYeXXd7cffx1k2v2ez0VP@W2BL2Wb38koHUhz01MFRiVMlL2@kzfeDVpv0rNOrevv2NOvz5CgP1G53Jw5xuENzZ4OWCX6ZcqeDNMV1G/3cDa6duvkC)
```
import java.util.*;         // Required import for List
m->{                        // Method with List parameter and integer return-type
  int t=0,s=0,i=0,          //  Temp integers
      r=0;                  //  Result integer
  for(;i<m.size();i++){     //  Loop over the List of Lists
    List l=(List)m.get(i);  //   Get the inner List
    for(;l.remove(0L););    //   Remove all zeros
    s=l.size();             //   Get the size of the List
    if(s>t){                //   If this size is larger than the previous
      t=s;                  //    Set `t` to this size
      r=i;                  //    And set the result to the index of this row
    }
  }                         //  End of loop
  return r;                 //  Return result-integer
}                           // End of method
```
[Answer]
# [Java (OpenJDK 8)](http://openjdk.java.net/), ~~119~~ 101 bytes
```
m->{int i=m.length,M=0,I=0,c;for(;i-->0;){c=0;for(int x:m[i])if(x!=0)c++;if(c>M){M=c;I=i;}}return I;}
```
[Try it online!](https://tio.run/##lZLPT8IwFMfv/BVPE5JNu2WAGmMtiRcTDpz0RjjU0mFx7Zb2TSHL/nYsGyoyTbRpt9fv@9FPm7firzzKC2lWi5et0kVuEVZei0tUWXxGex0tLY1AlZsfnQ6t5HrnKsqnTAkQGXcOplwZqHoAe9UhR/97zdUCtPcFD2iVWc7mwO3ShbtIgMd8YvB@f9qtMjibz@ZjSIHBVkfjyiugmI4zaZb4TKYsIRO/BE1zG1AVReOEhpVgSSPsotc3eqbmoUqD9QlLQnF@Tr0txtOwmjJBJ0zRurYSS2tgQustNIM2NCgdBikBI99gz9Ji7kY1qMnXJqn3dk0gCf@SnhCIvpfwmf@uMiDgZ9LO42oELruOIYHRbxk@/IqAjxgegIz@ep2LlqVLEV115UETH42O0NqE626No9cZNlB1z38OG6th/K2JyAc26MYEuS6kQLkIob3Iw8ah1HFeYlz43sQ0OO27G@i7vjkld9byjYsXUhaPedu7gQ4JpDEvimxz5/yhXmDss2pLWG/fAQ "Java (OpenJDK 8) – Try It Online")
Java, that sweet verbose language :)
Thanks for saving 18 bytes, @KevinCruijssen ;)
[Answer]
# JavaScript (ES6), 51 Bytes
```
m=>m.reduce((a,e,i)=>e.filter(x=>x).length>a?i:a,0)
```
where `m` is a 2D array and the index returned is 0-indexed
**Test cases:**
```
f=
m=>m.reduce((a,e,i)=>e.filter(x=>x).length>a?i:a,0)
console.log(f([[1], [0]]))
console.log(f([[0,-1], [0,0]]))
console.log(f([[1,1,0,0,0], [0,0,5,0,0], [2,3,0,0,0], [0,5,6,2,2]]))
console.log(f([[0,4,1,0], [0,0,-6,0], [0,1,4,-3], [2,0,0,8], [0,0,0,0]]))
```
[Answer]
# Java 8, 100 bytes
```
m->m.indexOf(m.stream().map(z->{z.removeIf(x->x==0);return z;}).max((q,r)->q.size()-r.size()).get())
```
## Explanation
The power of Lists and Streams! (and without the imports, to boot!)
Let's break this little lambda down into chunks:
```
m.stream().map(z->{z.removeIf(x->x==0);return z;}
```
We turn our List of Lists (the matrix in the question) into a Stream and go through each element, removing all of those pesky zeroes from each sub-List. We need to explicitly return the sublist each time here, because `Stream.map()` converts each object in the Stream to whatever the mapping returns, and we don't want to change them.
```
.max((q,r)->q.size()-r.size()).get()
```
We go through our newly de-zeroed sublists, and simply check how big they are next to each other, getting us the biggest sublist. The `.get()` is because the `Stream.max()` returns an Optional, requiring that extra function call.
```
m.indexOf()
```
We take that biggest sublist, and find where it is in the main List, giving us our result!
## Notes
This breaks if the outer list is empty, but I'm taking
> 
> You may assume that there will only be one row with the most non-zero elements.
> 
> 
> 
to imply that there will always be at least one row. Correct me if I'm wrong.
]