[Question]
  [
[Inspired](https://chat.stackexchange.com/transcript/message/58359892#58359892) by [Wzl](https://codegolf.stackexchange.com/users/90614/wzl)
Determine if a given square binary matrix has exactly one row or column consisting of entirely `1`s, and the rest of the matrix is `0`s.
For example, these are all true:
```
0 0 0 0 0 0 0 0 0    0 0 0 0 0    1 0 0 0    0 1
0 0 0 0 0 0 0 0 0    1 1 1 1 1    1 0 0 0    0 1
0 0 0 0 0 0 0 0 0    0 0 0 0 0    1 0 0 0
0 0 0 0 0 0 0 0 0    0 0 0 0 0    1 0 0 0
0 0 0 0 0 0 0 0 0    0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1
```
And these are all false:
```
0 0 0 0 0 0 0    0 1 0 0 0    0 1 0 0    0 0 0    0 0 0    0 0 1    0 1
1 1 1 1 1 1 1    1 1 1 1 1    1 1 0 1    1 0 1    0 0 0    1 0 0    0 0
0 0 0 0 0 0 0    0 1 0 0 0    0 1 0 0    0 0 0    0 0 0    0 1 0
1 1 1 1 1 1 1    0 1 0 0 0    0 1 0 0
0 0 0 0 0 0 0    0 1 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
```
The reasons for the false ones:
* More than one row
* More than one row or column
* There are `1`s outside the "all `1`s column"
* There isn't a row or column of all `1`s (describes the last 4)
You should take a square binary matrix of side length \$n \ge 2\$, in any reasonable format, and output 2 distinct, consistent values to indicate whether it has a single straight line. This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins.
---
**Keep your golfing in your code, not your inputs/outputs**. I'm very liberal with the I/O formats, including but not limited to:
* A multiline string
* A list of lines
* A 2D list (or matrix) consisting of two distinct consistent values (e.g. `0`/`1`, space/`'*'`, `5`/`'('`)
* A flat array, and \$n\$, as separate arguments
  
* Two distinct consistent values (e.g. `1`/`0`) to indicate the output
* Erroring/not erroring
* Two families of values, one of which consists of values that are truthy in your language and the other falsey (for example, natural numbers and zero)
  
* etc.
As a broad, general rule, so long as the input can be clearly understood and the outputs clearly distinguished, it's fair game.
---
## Test cases
| Input | Output |
| --- | --- |
| 
```
000000000000000000000000000000000000000000000000000000000000000000000000111111111
```
 | true |
| 
```
0000011111000000000000000
```
 | true |
| 
```
1000100010001000
```
 | true |
| 
```
0101
```
 | true |
| 
```
0000000111111100000001111111000000000000000000000
```
 | false |
| 
```
0100011111010000100001000
```
 | false |
| 
```
0100110101000100
```
 | false |
| 
```
1000010000100001
```
 | false |
| 
```
000101000
```
 | false |
| 
```
000000000
```
 | false |
| 
```
001100010
```
 | false |
| 
```
0100
```
 | false |
 
  
[Answer]
# [Python 2](https://docs.python.org/2/), 49 bytes
Takes as input a 2D binary matrix \$ a \$, and its size \$ n \$.
```
lambda a,n:sorted(map(sum,a+zip(*a)))[-2:]==[1,n]
```
[Try it online!](https://tio.run/##rU7BbsMgDL37K7gFb6yCHiPlS5IcWEM0pIQgoIfu5zNDEjWrtNsssP38/Gz7R/pa3HUdm26d9Pw5aKaFq@MSkhn4rD2P91no92/r@ZtGxPbjWvdN0yrh@tXOnhpZfEQYl8BuOhpmXcaXmAbrLsHogSOBQHqKfrKJV53rXIU1bIKmhCdXIdAQT/U23f1kyhXWJcEsIst7bF6SRT0wH4hiIzV4wSbjeK4jrvIw@J9MHQZwKsCpbfegCvvbgVT5wcu0P/FrJPFpZ8nPvgRi5UZujsQKdlQ2Q@HlDo5fTpM/ "Python 2 – Try It Online")
There may be shorter approaches, but this is what I could find for now. Please let me know if the algorithm is incorrect.
## Explanation
Since there is exactly one line, there should be exactly one row/column which contains \$ n \$ ones. Furthermore, since every \$ 1 \$ in the matrix exists on that line, there can be no other row/column containing more than one \$ 1 \$. Since if there were another \$ 1 \$ existing somwhere not on that line, it would create a row/column with at least two \$ 1 \$s.
Given this, it suffices to check that the two rows/columns with the largest number of \$ 1 \$s have counts of `[1, n]`.
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 8 bytes
```
{z|}≡ᵛ+1
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXV3@cOuERx3LH@7a8XBXZy2Qo5ZzePujpibrhzsXZT1q6k23VlKoqakJU1CqSgbKAhWB1FQ/atvwqKkFqFGppKg0VU@pBsRMS8wpBrJrQYp2bIOa97@6qqb2UefCh1tnaxv@/x8dHW2go4AdxeooDCdJQx0F7CgWJBuNXz2G6UQIgI01RDeTGB7MQTBrsTkRr8dwBAbpqkkQhjuaYCgaopuFTwDNWISZBhgGovGQwwwRwMi@xVCChYkeFwbocYHiS7TQQeMRTBFwtYZovNhYAA "Brachylog – Try It Online")
```
{z|}        Either the rows or the columns
    ≡ᵛ      are all the same list
      +1    which sums to 1.
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 47 bytes
```
->m,n{m.uniq[1]?m-[[0]*n]==[[1]*n]:m[0].sum==1}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y5XJ686V680L7Mw2jDWPlc3OtogVisv1tY2GsgHMqxygQJ6xaW5traGtf8LFNKigSp0DHQMY3XQ6Fgd41guXAoMCSkAQkImYCgwgOvUiTaEW/EfAA "Ruby – Try It Online")
### Explain please:
Split the two cases:
* If m has at least 2 different rows, remove all zeros and check if we are left with a single row consisting of ones.
* If not (all the rows are the same), check that the sum of the first row is one.
[Answer]
# [Factor](https://factorcode.org/) + `math.unicode`, 59 bytes
```
[ [ concat Σ = ] keep dup flip [ all-equal? ] bi@ or and ]
```
[Try it online!](https://tio.run/##3VRLTsMwFNznFHMBooaPECAoO8SGDWJVdWEct1h1bWM7UqvIp@E@XClYBERI7dAgsSFeJJl5fmPPe3oLQp0yzcP97d3NOYi1ilqsmJFMwLLniknKLNbEPeWV5FSVDNow57bacOm@QnK2cYZYLI2qNJdLXGRZnSE8Nc7QfrV/k53l/zVb7KyW9eH9YdBJwqB4Gv9j7H5o5wDH3w5QROV/g3UkDnt37N8jYsvpQN@kHfZ/tmccM1DfYkR9i6jcPmiyvp@BfflJQjyNdSSOIsXqN0bM6NGJhpERHdfd4psZZqBKUuLw@oJLzMMUZBplpbEQXAeWCHEQxh0R00A@8msoAyJLzJs65HgfnVdropE3bw "Factor – Try It Online")
Takes \$n\$ and a matrix of \$1\$s and \$0\$s, in that order.
* `[ concat Σ = ] keep` Is the sum of the matrix equal to \$n\$?
* `dup flip [ all-equal? ] bi@ or and` And are all the rows in either the original matrix or its transposition equal?
[Answer]
# JavaScript (ES6), 46 bytes
*Thanks to [@PertinentDetail](https://codegolf.stackexchange.com/users/103228/pertinentdetail) for a bug fix*
Expects a multiline string with a trailing line feed. Returns a Boolean value.
```
s=>/^(0*10*\n)\1*$|^(0+\n)*1+\n[^1]*$/.test(s)
```
[Try it online!](https://tio.run/##rVBNj8IgEL3zK4gxKWBE5mzqbfcPeFzWpKnUxTTgMuwmRve3V1rUVBNvO4E3bz6YR2Zf/VZYB3uIc@e3pmvKDsvVYsOUACW04xrE9JzCWeICEn5s4FNMFzIajAx5F8z3jw2GFQ0WXAZTbd9ta9ZHVzPFZfTrGKzbMS7x0NrIJtppN@Gy8eGtqr8Y0nJFT4RSpLOSFtoVyxTU3qFvjWz9jjVJhS/JH@8AgCilhttDtn9icLPr6Jwgo7YrEhiqj0AU9Of@rdu4l/GzT69HogMf4@BSVeViBpLl4b6Q0Xb65AU "JavaScript (Node.js) – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
S;§ṢIṪ‘=L
```
[Try it online!](https://tio.run/##y0rNyan8/z/Y@tDyhzsXeT7cuepRwwxbn/8Pd2@xfdQw1/Bwu@Z/Axjgog7LEAa4uJAEuJCUQUkuQ7AsKsFlYAhCSCIGhjACWa0hQgOqvTj56DTYTLjr4FbBSIiVQHsMkV0AcQDYUAgHhsHuBlKp/9Vj8tT1svIz8zQyS1KLNDLzCkpLdNRT1TU19YoLcjJLNIAKgEo0AQ "Jelly – Try It Online")
Slightly modified port of dingledooper's algorithm.
### How it works
```
S;§ṢIṪ‘=L    Monadic link; input = matrix M
S;§          Column sums of M ++ Row sums of M
   Ṣ         Sort
    I        Increments; (next - previous) for each adjacent pair
     Ṫ       Last item
      ‘      +1
       =L    Equals the length of M?
```
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
ZEȯE×SS=L
```
[Try it online!](https://tio.run/##y0rNyan8/z/K9cR618PTg4Ntff4/3L3F9lHDXMPD7Zr/DWCAizosQxjg4kIS4EJSBiW5DMGyqASXgSEIIYkYGMIIZLWGCA2o9uLko9NgM@Gug1sFIyFWAu0xRHYBxAFgQyEcGAa7G0il/lePyVPXy8rPzNPILEkt0sjMKygt0VFPVdfU1CsuyMks0QAqACrRBAA "Jelly – Try It Online")
Slightly modified port of chunes's algorithm.
### How it works
```
ZEȯE×SS=L    Monadic link; input = matrix M
ZE           1 if transpose(M) has all rows equal
  ȯE           or M has all rows equal, 0 otherwise
    ×SS      times column sum, and sum again
             (= times the sum of the entire matrix)
       =L    equals the length of M?
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/mathematica/), ~~21~~ ~~13~~ 35 bytes
```
Norm@#==#2&&Norm@Eigenvectors@#>#2&
```
[Try It Online!](https://tio.run/##zVM9C4NADN39FQGh0w1nPygdLC5dS6GjOEgR66BSe3Qp/nar9azxzFkRKcWAyb3kmbyLsS@uQeyL6OIXoV0c0yx2TNs2l4vF2z9EYZA8gotIs7tj7svz4pRFiQAndJ9PzpQnZ391ZjHlyXN2vmXC3XmeQc2BazCn1pd8my6fhdj0nqxdq73UX/70utT0Ss2o6jACH45lD9tejxq9LMRD@bReEpdsHHMhT6dXq@pnviZ3Red237pcyUbeA1SXDKXx0nIGTQTsHfEakBiK1BnkukBLhq0l/gYaAGQC79cNgYhmQjXimFxdSQTNPwpIpIlsDVh1NZBAq9wHFZox1ZTVNPOINJ9GygZMWEPdIg1W/2CRihc) (Thanks to @ZaMoC for configuring this.)
Takes `#` as the matrix, and `#2` as the square root of the side length, n. Returns True if the conditions are met, and False otherwise
**Explanation**
In Mathematica, the `Norm` function, when applied to a matrix, will perform a singular value decomposition and then identify and return, from among the resulting matrices, the element with the largest value. For most square binary matrices with n ≥ 2, the conditions will be met IFF the `Norm` of the matrix equals sqrt(n), i.e., if the following returns True:
```
Norm@#==#2& 
```
However @Nitroden found an exception, which can be generalized as follows: If sqrt(n) is an integer, and the matrix contains a sqrt(n) x sqrt(n) submatrix that is all 1's, and has 0's everywhere else, its `Norm` will also equal sqrt(n).
Thus, to eliminate those, I added an additional test: that the `Norm` of the `Eignevectors` of the matrix is greater than sqrt(n).
My *Try It Online!* link contains all the OP's test matrices and, at the end, Norden's case plus three additional matrices of that form. These now all return False.
Alas, Mathematica's `Eigenvectors` function is 12 bytes.
Thanks to @Bubbler for the tip that my `If` wrapper was unnecessary.
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 12 bytes
```
:∑$v∑Js¯Nt›=
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%3A%E2%88%91%24v%E2%88%91Js%C2%AFNt%E2%80%BA%3D&inputs=%5B%5B0%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%5D%2C%20%5B0%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%5D%2C%20%5B0%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%5D%2C%20%5B0%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%5D%2C%20%5B0%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%5D%2C%20%5B0%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%5D%2C%20%5B0%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%5D%2C%20%5B0%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%5D%2C%20%5B1%2C%201%2C%201%2C%201%2C%201%2C%201%2C%201%2C%201%2C%201%5D%5D%0A9&header=&footer=)
Yay! Beating Lyxal by 1 byte with a different approach!!!
-1 byte from @Lyxal himself thanks
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 8 bytes
Based on the first part of [Bubblers Jelly answer](https://codegolf.stackexchange.com/a/229886/64121), which uses dingledooper's algorithm.
Input is a 2d matrix and the side length, output is `1` for truthy inputs and any other integer for falsy ones. This is the definition of truthiness in 05AB1E.
```
Dø«O{¥θα
```
[Try it online!](https://tio.run/##yy9OTMpM/f/f5fCOQ6v9qw8tPbfj3Mb//6OjDXQUsKNYHYXhJGmoo4AdxcZyWQIA "05AB1E – Try It Online") or [Try all cases!](https://tio.run/##yy9OTMpM/X9o2aEVjxrmcXEdWqjOdW7LoYWPmtYAUTBXWWV65X@XwzsOrfavPrT03I5zG/@72J@boaSgcXi/ppLOfyUlJS4DGKASyxAGuLiQBLiQlEFJLkOwLCrBZWAIQlxopuHko9NAzUh2gtnIJJgCyhpAJCEEF8R2sKEQDgyDXWPABQwmAA "05AB1E – Try It Online")
```
D         # push two copies of the input matrix
 ø        # transpose one copy to get a list of columns
  «       # concatenate to the list of rows
   O      # sum each sublist
    {     # sort the row and column sums
     ¥    # take consecutive differences
      θ   # get the last one (largest value - second largest value)
       α  # absolute difference with the second input
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 bytes
```
S;§>Ƈ1⁼LW$
```
[Try it online!](https://tio.run/##y0rNyan8/z/Y@tByu2Ptho8a9/iEq/x/uHuL7aOGuYaH2zUj/xvAABd1WIYwwMWFJMCFpAxKchmCZVEJLgNDEOJCMw0nH50GakayE8xGJsEUUNYAIgkhuCC2gw2FcGAY7BqIGNhMiD1c6M4HYkMIwZX6Xz0mT10vKz8zTyOzJLVIIzOvoLRERz1VXVMz2krXMFavuCAns0QDqAqoThMA "Jelly – Try It Online")
Uses Unrelated string's test suite.
Fixed with some help from Unrelated string.
## Explanation
```
S;§>Ƈ1⁼LW$
S           sums of columns
 ;          concat with
  §         sums of rows
    Ƈ       keep the sums which are:
   > 1       greater than 1
      ⁼LW$  = [length] ?
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
ŒṪZEƇȧiɗJ
```
[Try it online!](https://tio.run/##y0rNyan8///opIc7V0W5Hms/sTzz5HSv/w93b7F91DDX8HC75sOd@x41rYn8bwADXNRhGcIAFxeSABeSMijJZQiWRSW4DAxBiAvNNJx8dBqoGclOMBuZBFNAWQOIJITggtgONhTCgWGwayBiYDMh9nChOx@IDSEEV@p/9Zg8db2s/Mw8jcyS1CKNzLyC0hId9VR1Tc1oK13DWL3igpzMEg2gKqA6TQA "Jelly – Try It Online")
The *fourth* totally different Jelly 9 byter. Returns either 1 or 2 for truthy and either an empty list or the number 0 for falsy. Also the program structure is more convoluted.
### How it works
```
ŒṪZEƇȧiɗJ    Monadic link. Input: the matrix M of size n
ŒṪZ          Take the transpose of multi-dimensional indices of 1
             the result is a 2-row matrix X;
             in order to satisfy the condition, one of the rows must be
             all-equal, and the other must be identical to 1..n
   ....ɗJ    A dyad with ^ as left arg and 1..n as right:
   EƇ          Collect every row that is all-equal from X
     ȧ         Chain onto Python's `and`...
      i        Get 1-based index of 1..n in X, 0 if not found
```
[Answer]
# [J](http://jsoftware.com/), 25 bytes
```
(1:0}0"0)e.],&(#\|."{])|:
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/NQytDGoNlAw0U/ViddQ0lGNq9JSqYzVrrP5rcnGlJmfkKxgq2CqkKSjpKRlY68UbKcSCDDDgMoABKrEMYYALZq8BVnsNaW4vHv9CVHMhmQEl8es1BGtFJfD7Es11OPnoNAFTDZH8AGYjk5r/AQ "J – Try It Online")
Not the shortest (my previous translation of dingledooper's was a couple bytes shorter), but I wanted to come up with a different approach:
* `(1:0}0"0)` Is the matrix with all ones in the first row and zeros elsewhere...
* `e.` an elment of...
* `],&(#\|."{])|:` All possible rotations of the input, and all possible rotations of its transpose, catted together?
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
,ZfJṁ=ⱮJƲ
```
[Try it online!](https://tio.run/##y0rNyan8/18nKs3r4c5G20cb13kd2/T/4e4tto8a5hoebn@4sw2INCP/G8AAF3VYhjDAxYUkwIWkDEpyGYJlUQkuA0MQ4kIzDScfnQZqRrITzEYmwRRQ1gAiCSG4ILaDDYVwYBjsGogY2EyIPVzozgdiQwjBlfpfPSZPXS8rPzNPI7MktUgjM6@gtERHPVVdUzPaStcwVq@4ICezRAOoCqhOEwA "Jelly – Try It Online")
[Idea stolen from Razetime in TNB](https://chat.stackexchange.com/transcript/message/58362379#58362379)
```
,            Pair the input with
 Z           its transpose.
  f          Filter the pair to elements contained in
   Jṁ=ⱮJƲ    every matrix of the same dimensions with a single column of 1s.
   Jṁ        Mold [1 .. len(input)] to the shape of the input.
      ⱮJ     For each 1 .. len(input),
     =       is each element equal to it?
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 25 bytes
```
#||#/.{a_..}:>Tr@a==1&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7X7mmRvl9f7u@XnVivJ5erZVdSJFDoq2todr/gKLMvJJoZV27NIeQfNeKgqLU4uLM/DwH54zEosTkktSiYofgEqCa9OCCnEygQh0lLqVYMKFWF5ycmFdXzaVkAANc1GEZwoCSDtRwiBAXkkIICVJgCJZHIcD6gMoRBiBM5cLFR6MhZiDZDWYjkTAFQHkDiDSYgFrJBRZEcKEY5jIDJa7a/wA "Wolfram Language (Mathematica) – Try It Online")
Returns `True` if the matrix has a single line, and non`True` otherwise.
```
#||#                   input OR its tranpose
     /.{a_..}:>         replace lists of repeated elements with
               Tr@a==1      (is the sum of that element equal to 1?)
```
Then, any `Or` expression with `True` as an argument gets reduced to `True`.
[Answer]
# [Python 2](https://docs.python.org/2/), 43 bytes
*Heavily based on [dingledooper's answer](https://codegolf.stackexchange.com/a/229880/16766), which you should upvote.*
```
lambda a,n:set(map(sum,a+zip(*a)))=={0,1,n}
```
[Try it online!](https://tio.run/##rU7BbsMgDL37K7gFb6iCHSvlS5YdWEM0pIRYQA/dtG/PDEnUrNJus8D28/OzTbf8MYeXZWi7ZbTTe2@FVeGcXJaTJZmuk7LPn57kk0XEtv3SyqjwvfiJ5phFuiUY5iguNjnhQ8GnlHsfTtHZXiKDyGKONPosmy50ocEzrIK2hjvXIPAQ4vprvtLo6gk@ZCU8oih7fFlSRG8gKDIlBm4gJUYXZKkjLno3@J/M7AZwKMChbfNgKvvbgTblwcO0P/FjZPFhZ82PvgZm9UqujsUGNlQ3Q@X1BvZfT9M/ "Python 2 – Try It Online")
Or:
### [Python 3](https://docs.python.org/3/), 44 bytes:
```
lambda a,n:{*map(sum,a+[*zip(*a)])}=={0,1,n}
```
Saves bytes with set unpacking, but loses bytes because `zip` doesn't return a list. [Try it online!](https://tio.run/##rU5BjsMgDLz7FdyCU1SBequUlzQ90E2iRUoIAnpoq749NSTRZiv1Vgtsj8dj293i72gPU1fVU6@HS6OZFvb4KAfteLgOQu9O5d04Xmo847OqHlIoYZ@TGdzoIwu3AN3o2Y8OLTM24X2IjbF73@qGIwFPaoquN5EXta1tgUeYBVUOf1yBQEMc1U/x6vqWpyuMjYIZRJb2mLQkic7AnCeKd9TgBOtby1MdESe5GnwnU6sBbAqwaVs8qMz@dyBVevA27SN@jyTe7Mz51udArJzJ2ZFYwYLyZsi8XMD682nyBQ "Python 3 – Try It Online")
### Explanation
In a truthy input, the sum of a row or column must be one of these three numbers:
* \$0\$, if it is parallel to the line of \$1\$s
* \$1\$, if it is perpendicular to the line of \$1\$s
* \$n\$, if it is the line of \$1\$s
Any number other than these three indicates the existence of multiple lines or a partial line.
Furthermore, all three of these numbers must be represented among the list of sums:
* If \$n\$ is missing, there is no row or column that contains all \$1\$s.
* If \$1\$ is missing, there are multiple rows and columns containing \$1\$s.
* If \$0\$ is missing, the input has two perpendicular lines of \$1\$s (as in the second falsey test case). Conveniently, we don't have to worry about the case of a \$1 \times 1\$ matrix, because we're given that \$n \geq 2\$.
Therefore:
```
set(                  )           # The set of
    map(sum,         )            # the sums of each
            a+                    # row and
              zip(*a)             # column
                       ==         # must be exactly
                         {0,1,n}  # that set
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 32 bytes
```
^(0*10*)(¶\1)*$|^(0+¶)*1+(¶0+)*$
```
[Try it online!](https://tio.run/##K0otycxL/P8/TsNAy9BAS1Pj0LYYQ00tlRqggPahbZpahtpAIQNtoND//wYgwGUIAlwQNhIJAA "Retina 0.8.2 – Try It Online") Turns out to be much like @Arnauld's answer, except I wanted to solve it for no trailing newline instead.
[Answer]
# [Julia](http://julialang.org/), 37 bytes
```
x$n=(l=sum([x x'],dims=1))[l.>1]==[n]
```
[Try it online!](https://tio.run/##tZBBCsMgEEX3nmIWgSpI0QPYi4iLgBYsxoY4AdvLW2tIWrvvzGb@m/8ZmNsa/ChzKXmIigaV1onqDPlkuPVTUpIxHc4XaZTS0RR0CRMooJoI6PrvWkLXxHBd2b7bXL@gmUQ1iyPwnsUe/uKb6zjcUfmhhJHrfQEEH6E9g0At69McxgdF1uS8@Igh0l7hkPzTUeT1p8RFW14 "Julia 1.0 – Try It Online")
uses [Razetime's approach](https://codegolf.stackexchange.com/a/229881/98541)
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 14 bytes
```
:ÞTJv∑s2Nȯ1?"⁼
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%3A%C3%9ETJv%E2%88%91s2N%C8%AF1%3F%22%E2%81%BC&inputs=%5B%5B0%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%5D%2C%20%5B0%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%5D%2C%20%5B0%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%5D%2C%20%5B0%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%5D%2C%20%5B0%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%5D%2C%20%5B0%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%5D%2C%20%5B0%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%5D%2C%20%5B0%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%2C%200%5D%2C%20%5B1%2C%201%2C%201%2C%201%2C%201%2C%201%2C%201%2C%201%2C%201%5D%5D%0A9&header=&footer=)
Another stealing of the python answer.
## Explained
```
:ÞTJv∑s2Nȯ1?"⁼
:ÞTJ           # merge the input list with itself transposed.
    v∑s        # sort the list that results from getting the sum of each item
       2Nȯ     # take the last two items of that list
          1?"⁼ # and check for equality with the list [1, second_input]   
```
[Answer]
# T-SQL, 152 bytes
Input is a table variable
Returns 1 for true, 0 for false
To save bytes, this can only handle matrix up to length 10
```
SELECT top 1iif(x=replace(a,0,'')or
sum(x)over()=x*2-1and a not like'%0%'and
0=min(a)over(),1,0)FROM(SELECT
rank()over(order by a)x,*FROM @)c ORDER BY-x
```
**[Try it online](https://data.stackexchange.com/stackoverflow/query/1423953/is-there-a-single-straight-line-in-the-matrix)**
[Answer]
# [tinylisp](https://github.com/dloscutoff/Esolangs/tree/master/tinylisp), 88 bytes
```
(load library
(d _(q((M)(e 1(*(sum(map all M))(sum(map any M
(q((M)(+(_ M)(_(transpose M
```
The solution is the anonymous function in the last line. [Try it online!](https://tio.run/##fcoxCoAwFAPQ3VNkTHXRS7j1DOWLDoVvra0OPX1VENxMlgTe4UNRn2Ot1E1mqJ@SpNJwhuNOWsMFA1vmc@UqEaIKa8z3Q4F9@Pjyju4GdDyShBy3vMBWjuAOckD/1OB33akX "tinylisp – Try It Online")
Here's an ungolfed version that verifies all test cases: [Try it online!](https://tio.run/##zVK7EoMgEOz5iiuPTvID6dL5Dc45mBln8IkWfr0B4gPQmJSRZm@5W/Z2HMp6UqVu5xlVQxJUmffUT5yhLJ6QMUBFVS4JMOUMAItuJHUHYTBgNaqbBYB6rExJLZBSkHIes/VkWfu9hR8HYZLSaWEGjrAAh55q3Ta6WKZnp2aHO0DGEBOIjhn9R1JAdEwQvv2gJ1C5KJyE8AWu4PLgoh4bODV6WOe3ji/EauTj5sKfPC18iVUgCcZ9GOcUtLhiN@nnsqa3bxldRmC7FFvu23NR/K62P/QL "tinylisp – Try It Online")
### Explanation
Define a helper function `_` that takes a matrix (list of lists) `M`:
```
      (sum(map all M))                    Number of rows that are all 1s
                      (sum(map any M))    Number of rows that have any 1s
    (*                                )   Multiply those two numbers
(e 1                                   )  Is the product equal to 1?
```
In other words, is there exactly one row that has all 1s, which is also the only row that has any 1s?
Then our main function needs only apply `_` to the matrix and its transpose, and return truthy if either result is truthy:
```
  (_ M)                   Test M
       (_(transpose M))   Test transpose(M)
(+                     )  Add the two results
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 27 bytes
```
ＷＳ⊞υι∨∧⁼⌊υ⌈υ⁼¹Σ⌈υ⁼ΦυΣι⟦⭆⌈υ¹
```
[Try it online!](https://tio.run/##TY2xDsIwDET3foVHRwoSmTsxgMQQUakjYohKRSyloU1j4O9DonaIB@t8z2cP1oThbVxKX0tuBLz6mWMfA/kXCgEdrxZZAom26bIZ8Rbw5J94Xti4FTV5mnhCFhK0@e06DztXEvpsVaiCF3JxDOV82aFC7ttrbeYqI0GJRw62KR1LNapUs@m6p8PH/QE "Charcoal – Try It Online") Link is to verbose version of code. Takes input as a newline-terminated list of strings. Explanation:
```
ＷＳ⊞υι
```
Input the matrix.
```
  ⁼⌊υ⌈υ                 All rows are identical
 ∧                      Logical And
         Σ⌈υ            The sum of a row
       ⁼¹               Equals literal `1`
∨                       Logical Or
              υ         Input array
             Φ          Filtered where
                ι       Current row
               Σ        Is non-zero
            ⁼           Equals
                  ⭆⌈υ¹  Row of 1s
                 ⟦      As a 1-row 2D array
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~63~~ 55 bytes
```
{(F⍉⍵)+(F←{(1↑⍴⍵)=(+/,⍵)×+/∧/⍵})⍵}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///v1rD7VFv56PerZraQFbbhGoNw0dtEx/1bgEJ2Wpo6@uAGIena@s/6liuD2TXaoKI/2lAtY96@x51NT/qXQNUfmi9MUhf39TgIGcgGeLhGfw/TcFYwRgoZ6AAgoZgCGZzpSmYKJjAZWByUFkE5EKYYAhVByWBMkYKRlAZQyJMhPLRTISpAWIA "APL (Dyalog Unicode) – Try It Online")
* changed approach
* F used on input + input transposed
```
×+/∧/⍵  ⍝ number of all 1s lines multiplied by
(+/,⍵)    ⍝ total 1s 
(1↑⍴⍵)=  ⍝ equal to side length?
```
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), ~~49~~ ~~45~~ 46 bytes
inspired by [Arnauld's](https://codegolf.stackexchange.com/a/229896/80745) and [Neil's](https://codegolf.stackexchange.com/a/229900/80745) answers.
+1 bytes with additional Test cases.
```
"$args "-match'^(0*10* )\1+$|^(0+ )*1+ [0 ]*$'
```
[Try it online!](https://tio.run/##tVPLasMwELzrKxajVpYfIF0DhXxDe@wL4ypNQW0Sy6aFJN/uqnq4iixILtnLanc8s7My2m6@RafWQsoRr@AO9mOGm@5dQVZ/Nn27Ji85KzgrgD7xEh90VQIteAmPDJ4LTMYjQsscoSrHfTeIChHmg1y34D4InY2fcBJ2osMJjXtWKp8OsKJ@7KqRKlg7cEYu6SaOZ3TZeYVLdDnjbsFEjizw2ZX6TnSY8yyNTawpx24CyHie9kxctPPpPkjjQYpx7n6sGzhzbXl/bQoHuIE9Ah1Y/GxF24u3CrD8@BJKvxb8aqFOqEH2unGrH9HSoMggpLZBTJU9DG0rlFoAzj2nFrt/aVrBvWkvvGZmB1jJ4/gL "PowerShell – Try It Online")
* convert the arguments to a string with space char as separator
* add the trail space char
* match with regexp
[Answer]
# [GNU-APL](https://www.gnu.org/software/apl/), 34 bytes
```
{+/(⍺≡+/,⍵)∧(⍵∧.=⍺⍴1)∨((⍺⍴1)∧.=⍵)}
```
Input the size of the matrix, and the matrix itself.
```
⍵∧.=⍺⍴1    finds the row with all ones, a1=1∧a2=1∧a3=1 ...
(⍺⍴1)∧.=⍵  finds the column with all ones
           The disjunction of the above two ensures atleast one of them happends
⍺≡+/,⍵     ensures that only required numbers of ones are present 
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~121~~ 119 bytes
*-2 bytes thanks to ceilingcat*
```
l;e;r;o;a;f(m,n)int*m;{r=l=o=0;for(e=a=~0;r++<n;o|=*m,a&=*m++)~*m<<32-n?e&=!*m:++l;for(o-=a;a;a/=2)l+=a&1;r=l<2&&e^!o;}
```
This has entire rows stored in integer arrays, making the maximum matrix size 32.
[Try it online!](https://tio.run/##vVFNj5swEL37V0yQwkLsiI@0qhpjrfZSqVIPlfbY3UoWcVpSMBFQNdJu9q@ntsFANqRVL0UJHmbmvXlvnC6/penplFNBK1pSTrdeQaSfyWZR0KeK5axkId2WlScYZy8hrTBOJC2f2aIg3FVvjP2XRZEkq3gpb4XLZotijXFuMOWSccXJAxb7OWbcjaiiTGLXFV9nJT2e1BwoeFNlhy@r@JGiuqmasvDS77xS/KDL0n9CAJpNf2XAIKTqSEBSwDgzVbAk2aOpm5SF7FrIzkJ2HWQMShIGEe3S2RY87QtmDG7CG79Lj/uf@/ZjOx5jCkFQ/8j2IMWvPJMC6doRoUbUzbmh9hCHvUgbsfHByOmc6@Ub4iC4bhn2lSpsPWd@eJAOGXS1UA2qRP0zbxRS3aepWl5d3PO6ViXbw3ot3eSevl7DfAOeOOjTV//DfPMg57WZqllunc939/fO2vlw9/GTyrWUpCck2q36Fe3wvxD/E6liVNsteCY9daFmy8gJ7aPI/sdXZB8tHr0nEClZYy1D14C@EhH0lozgUY@@FhD0ZgwIuxGtlpi8lnIueWzmj/npmKB3JBzPnvDa5y4j7fUVvEOHA3gcaK/hxHKGPhVZjdElYFhd79A0raaazs@LpsheglUw0WSndHehS8fTbw "C (gcc) – Try It Online")
[Answer]
# [jq](https://stedolan.github.io/jq/), 38 bytes
Reads a 2D array, outputs a boolean.
```
(.+transpose|map(add)-[0,1])==[length]
```
[Try it online!](https://tio.run/##yyr8/19DT7ukKDGvuCC/OLUmN7FAIzElRVM32kDHMFbT1jY6JzUvvSQj9v//aC4FBaAoGozVGRLChjpoMJYrlgvVR2gK0YwjwIWZZohqFiEOwhFw@7C4DIc3sHiYFFUEhZAchzeEDFGNwMFFMw1hlgGaSagcrAGLphLMRfYBWhgiwhw5NLCpwWAiqzFEijskd2CLRJAgAA "jq – Try It Online")
]