[Question]
  [
Take a non-empty matrix / numeric array containing positive integers as input. Return, in this order, the sums of the first row and column, then the second row and column and continue until there aren't any more rows or columns.
Suppose the input is:
```
2   10   10    2    4
9    7    7    2    9
1    7    6    2    4
7    1    4    8    9
```
Then the output should be:
```
45, 33, 16, 17
```
Because: `2+9+1+7+10+10+2+4=45, 7+7+1+7+2+9=33, 6+4+2+4=16, 8+9=17`.
## Test cases:
Test cases are on the following format:
```
Input
---
Output
```
```
5
---
5
..........
1  4
----
5
..........
7
2
---
9
..........
 8    3    7   10    3    7   10    1
10    7    5    8    4    3    3    1
 1    6    4    1    3    6   10    1
 2    3    8    2    8    3    4    1
---
62   40   33   18
..........
30    39    48     1    10    19    28
38    47     7     9    18    27    29
46     6     8    17    26    35    37
 5    14    16    25    34    36    45
13    15    24    33    42    44     4
21    23    32    41    43     3    12
22    31    40    49     2    11    20
---
320  226   235   263   135    26    20
..........
7   10    1
4    4    2
6    3    4
1    4   10
5    7    6
---
34   20   20
```
As arrays:
```
[[5]]
[[1,4]]
[[7],[2]]
[[8,3,7,10,3,7,10,1],[10,7,5,8,4,3,3,1],[1,6,4,1,3,6,10,1],[2,3,8,2,8,3,4,1]]
[[30,39,48,1,10,19,28],[38,47,7,9,18,27,29],[46,6,8,17,26,35,37],[5,14,16,25,34,36,45],[13,15,24,33,42,44,4],[21,23,32,41,43,3,12],[22,31,40,49,2,11,20]]
[[7,10,1],[4,4,2],[6,3,4],[1,4,10],[5,7,6]]
```
---
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest solution in each language wins.
  
[Answer]
# [MATL](https://github.com/lmendo/MATL), 16 bytes
```
&n:w:!XlX:GX:1XQ
```
[Try it online!](https://tio.run/nexus/matl#@6@WZ1VupRiRE2HlHmFlGBH4/3@0kYKhAQgZKZhYWyqYA6GRgqW1IZA2A4uZKxgqmChYKFjGAgA "MATL – TIO Nexus") Or [verify all test cases](https://tio.run/nexus/matl#NY@9bgJBDIT7PMXQhArp7P29c5uKLlKKlRASD4BSJo9/fAui8Xq845nxbZz3z9/tfzuM@9jOY7Pxvf8djqfTcXz97Jdy/biYMrWFU7uSmmx5PxaUpqKuzCzNgSq90dcXw2m7XHOXD1QS@6tyhzUZq7xHQqEhtcogN/kauSIBCVCVilKLIkOiykEY4lTCcC1yIPqunJXDTU4cEOmfuTycIKBFGUMZjGXe9QrJkjzqjMgFeCx4NdXrAw).
### Explanation
Consider, as an example, the input 
```
2   10   10    2    4
9    7    7    2    9
1    7    6    2    4
7    1    4    8    9
```
The code `&n:w:!Xl` builds the column vector `[1; 2; 3; 4]` and the row vector `[1 2 3 4 5]`. Then `Xl` computes the minimum element-wise with broadcast, which gives the matrix
```
1 1 1 1 1
1 2 2 2 2
1 2 3 3 3
1 2 3 4 4
```
`X:` linearizes this matrix (in column-major order) into the column vector `[1; 1; 1; 1; 1; 2; 2; ... ; 4]`. This vector and the linearized input matrix, obtained as `GX:`, are passed as inputs to the `accumarray(... @sum)` function, or `1XQ`. This computes the sum of the second input grouped by values of the first input.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 3 bytes
```
ŒDS
```
[Try it online!](https://tio.run/nexus/jelly#@390kkvw////o6MVLHQUjHUUzHUMDZAYhrE6XArRIJa5joKpDkiRCVjaGCanYKijYAYWNQSLmiHpUzACCwE1GelAzQepi40FAA "Jelly – TIO Nexus")
## How it works
```
ŒDS
ŒD   diagonals
  S  vectorized sum
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), ~~23~~ 18 bytes
```
{[{(:+\z}h;]2/::+}
```
Anonymous block expecting the argument on the stack and leaving the result on the stack.
[Try it online!](https://tio.run/nexus/cjam#K6z7Xx1drWGlHVNVm2Eda6RvZaVd@7@u4H90tIKFAhAYgwhzIDY0wMI1jOWKhrBAYgqmIAKszQSu2BimTsEQxDKDyxrCZc1QzFMwgkuAjTKCs4wRemNjAQ "CJam – TIO Nexus")
### Explanation
```
[      e# Begin working in an array.
 {     e#  Do:
  (:+  e#   Remove the first row of the matrix and sum it.
  \z   e#   Bring the matrix back to the top and transpose it.
 }h    e#  While the matrix is non-empty.
 ;     e#  Discard the remaining empty matrix.
]      e# Close the array.
2/     e# Split it into consecutive pairs of elements (possibly with a singleton on the end).
::+    e# Sum each pair.
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~14~~ 11 bytes
```
[ćOˆøŽ]¯2ôO
```
[Try it online!](https://tio.run/nexus/05ab1e#Fc25DQJBEETRhL4xfewcUWwAo0kHwsHBwMFhwSKopfD6P5XU53xf9@/leHye63Xz476f55xRiEF2DCvYwPtiRicbjYF1vOFDmJWKhspKbEQTblhiFVcnUclNaoFtuCBIJ5OUuuFBqI3UgflfnVAXUs8xbcpaPw "05AB1E – TIO Nexus")
**Explanation**
```
[   Ž ]       # loop until stack is empty
 ć            # extract the head
  Oˆ          # sum and add to global list
     ø        # transpose
       ¯      # push global list
        2ô    # split into pairs
          O   # sum each pair
```
[Answer]
## JavaScript (ES6), 60 bytes
```
a=>a.map((b,y)=>b.map((c,x)=>r[x=x<y?x:y]=~~r[x]+c),r=[])&&r
```
Naive solution, may be a better way.
[Answer]
# [Octave](https://www.gnu.org/software/octave/), ~~63~~ 60 bytes
```
@(A)(@(L)sum(triu(A,1)')(L)+sum(tril(A))(L))(1:min(size(A)))
```
[Try it online!](https://tio.run/nexus/octave#XVK9TsQwGNv7FNlIBEPz0/YOhHS38wahI0MljoFwCy9f8tnNV5UlSmzX8ee0vL6vF3t19mLfXLnf7M/3crfXJ@8eXEUeN@izSuTsrH@@LV@2LL8fArm12JyDMcb3bTFyNGnu8lk2ky7AzxX3Co0HPSCQSZYT9bPrumIHV5f6ZZqxmV4C8Zypi82TGf4dvdza67WD2icVx6ZjglFZr@x48GPuqFZBd3H/dm4pI2OhkgQVjTc/4OFUbSNzISfTGpCel7BJaTEhIoPyXk8SSMSMcZKg2HoGYuMkOTwnHaQhdgAykOQofCEgeKiA6IG9keSzAdmqDCJkRyQxacIwLMvTpteSjg@WtEaxGvdm2y@UIK@nYf@hqtf6Bw "Octave – TIO Nexus")
The answer for this matrix:
```
2   10   10    2    4
9    7    7    2    9
1    7    6    2    4
7    1    4    8    9
```
is the vector of row sums of its upper triangular part:
```
0   10   10    2    4
0    0    7    2    9
0    0    0    2    4
0    0    0    0    9
```
plus the vector of column sums of its lower triangular part:
```
2    0    0    0    0
9    7    0    0    0
1    7    6    0    0
7    1    4    8    0
```
which is precisely what my answer is computing.
[Answer]
## Mathematica, 60 bytes
*Inspired by [Luis Mendo's MATL answer](https://codegolf.stackexchange.com/a/121443/66104).*
```
Pick[#,Min~Array~d,n]~Total~2~Table~{n,Min[d=Dimensions@#]}&
```
Explanation: `Min~Array~Dimensions@#` constructs a matrix like the following:
```
1 1 1 1 1
1 2 2 2 2
1 2 3 3 3
1 2 3 4 4
```
Then `Pick[#,...,n]~Total~2` picks out the entries of the input matrix corresponding to the number `n` in the weird matrix above, and sums them. Finally `...~Table~{n,Min[d=Dimensions@#]}` iterates over `n`.
This is 1 byte shorter than the naïve approach:
```
{#[[n,n;;]],#[[n+1;;,n]]}~Total~2~Table~{n,Min@Dimensions@#}&
```
[Answer]
## Haskell, ~~50~~ 49 bytes
```
f(a@(_:_):b)=sum(a++map(!!0)b):f(tail<$>b)
f _=[]
```
[Try it online!](https://tio.run/nexus/haskell#ZYzNCoMwEITvPsUKHhLcg1FrgtTS9whLSCiBQP2htc@fbile2tPwfTNMjsJfhRudHIOcnq9Z@Lqe/SbKspFBjlHsPt3P1SXIIoKbLOXZpwUmuK0FwPZIyw4VRLBWYU/04zShbf@swQ41quYIxSsOjSc02LPtvgoHJsU0HKuWwWCLnweuiPIb "Haskell – TIO Nexus")
If there's at least one row with at least one element, the result is the sum of the first row and the heads of all other rows followed by a recursive call with the tails of all other rows. In all other cases, the result is the empty list.
Edit: Ørjan Johansen saved a byte. Thanks!
[Answer]
# [Octave](https://www.gnu.org/software/octave/), ~~64~~ 52 bytes
*Thanks to @StewieGriffin for saving 1 byte!*
```
@(x)accumarray(min((1:size(x))',1:rows(x'))(:),x(:))
```
This defines an anonymous function.
[Try it online!](https://tio.run/nexus/octave#NU/LasMwELz3K@YWCYLxrp72Ush/hBxMaCCHtOAQ6vbn3XGVXKQZaXZm9oJ3dF23Htzip/P5cZvmefpxt@unczLer78f/PC7vYzz1/fdLTvv3ej3Cw@/XtwxnfwbL0FsoJg2UBFQIP3rEuNRkFAR@Ra2B2RiIc5NoYQVim2WH80o0GJArBRuogFaLdCk0G2AUF@gg8VMF4pIMkJCKJYgdMlQMmYyLJkwOEFJGaGIEdFUoGxExjX@q6kpu5D1iAyEUNE/F2xVOQe1vBXlHozpGVeQT379Aw)
### Explanation
The code is similar to my [MATL answer](https://codegolf.stackexchange.com/a/121443/36398) (see explanation there).
Two bytes have been saved using `1:size(x)` instead of `1:size(x,1)`, exploiting the fact that `1:[a b]` behaves the same as `1:a`. Also, one byte has been saved using `1:rows(x')` instead of `1:size(x,2)`, thanks to Stewie.
[Answer]
# [R](https://www.r-project.org/), ~~63~~ ~~60~~ ~~59~~ ~~57~~ 56 bytes
*Edit: -4 bytes, and then -2, and then -1 more, thanks to Robin Ryder*
```
function(m,`+`=sum)while(+m)show(m+-{m=m[-1,-1,drop=F]})
```
[Try it online!](https://tio.run/##jZBBCoMwEEX3cwxXCY7QaKzpwm0v0RYU26JgEomKhdKzp6NScNGFTBKG/D@fvDjfucYMlW2dnXL/HE01NNYwjUVY5P2o@VQ37YOFmve1nZgOo7fO9SUSSOvubJefbx/u6a4cXPNiFYMYTygwQxAHOjPq1@6IEkmcSyFIctHmKDls3sA0h6ocWHA1AQfY5KYcxU6roFCMd5ozcu5OBoXEIggBkgUpQcgwJRK1UKqfJklRs5asJtKSeZS@QOBS/8j9Fw "R – Try It Online")
Repeatedly removes the first row & column (using negative indexing: `m[-1,-1]` is `m` without the first row & column), prints the difference between the sum of `m` and this, and keeps going if there's anything left.
[R](https://www.r-project.org/) is very well-suited to this type of vectorized matrix operation, so this approach comes-out significantly shorter than [a looping approach](https://codegolf.stackexchange.com/a/121591/95126).
[Answer]
# oK, ~~19~~ 18 bytes
-1 byte [thanks to coltim](https://codegolf.stackexchange.com/questions/121425/sum-of-first-row-and-column-then-second-row-and-column-and-so-on/121434?noredirect=1#comment504604_121434).
```
1_--':+//'(1_+1_)\
```
[Try it online!](https://tio.run/##XVG7DoMwENvvK7KRCBDcJTz7K5XYWBj6/xMFG1LUJSH2xbHNVn@2fV9nXeq6mMumKbwupS7hva@F9@ac0/Ze3Hl0SaZzG/ICdBLNQP@YBQAqncuI2SBVd8wn8dXwqiyIJxFvCT73d1ThDskuq6U8GjnF5/rMaeb6hxYNxixj@Sv@bh7OIq0gcwJPwUsHuI0S6QXe6NCBUoqzqEkSbNEcX1NSQCJSxUEYT2mCdZJiWGY7KmRiUEaK5lk@kKNlg2FjR6T4R4BctZkYGyGFdAkRWI1SpA1h/wI "K (oK) – Try It Online")
Explanation:
```
          (1_+1_)   /a function that strips the top and leftmost rows of a matrix
                 \  /apply this function as many times as possible,
                    /    saving each result as one element of a list
      +//'          /for each result, get the sum of all numbers
  --':              /subtract every right value from every left value
1_                  /remove the extra 0
```
[Answer]
## [Julia](https://julialang.org/), 62 bytes
```
f=x->1∈size(x)?sum(x):(n=f(x[2:end,2:end]);[sum(x)-sum(n);n])
```
Works recursively by summing up the whole matrix and then subtracting off the sum of the next block. Probably not the most effective approach, but nicely intuitive.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 16 bytes
```
[ćOsø.g<NQ#])2ôO
```
[Try it online!](https://tio.run/nexus/05ab1e#Fc27DQIxEEXRYoiQrlaej38SNbAithxvARRBQwTkS19myOYePWnW@L725/nZjtv9cZlXPd/7WmNYwjreECQhHW2TYQ2vVDrS0Ir2QC8UYhhZsIzVwIw4UtBoxwqeQ8WQjAYYrrjjoSqoYdGCx4HoXxWLTng8R2KT5vwB "05AB1E – TIO Nexus") or [Try all tests](https://tio.run/nexus/05ab1e#NY9NCgIxFIMP40oIMn39HfAMDq5L1x5AEDyBF3LhfrzX@LUym74mTZO8x3Or39dyXz@n2/lyPbSjre9l01Zrja2pVqcwZuawcSvyynLTPhwkIyuqKMD6P6UEcqC0qwxQZOoOPA03j8@sUFB21Swr0B6njOUsx4csmyFDwgohMMlH@d4pymGVZGDCyYw9nA5RBkGSKQS2IN/JqAdmq9HTOkst8KRAuByaqbX2Aw "05AB1E – TIO Nexus")
```
[                # Start loop
 ć               # Extract first element
  O              # Sum
   sø            # Transpose the input array (without the first N rows and columns)
     .g<NQ       # Push if (stack height - 1 == loop count)
          #]     # If they were equal break
            )2ô  # Break stack into chunks of 2
               O # Sum the chunks
```
[Answer]
# Vim, ~~66~~, 52 bytes
```
qq^f j<C-v>}dkV}Jo<esc>p@qq@q:%s/\v> +</+/g|%norm C<C-v><C-r>=<C-v><C-r>"<C-v><cr><cr>
```
[Try it online!](https://tio.run/nexus/v#JY8xC8JADEb3jB26uAShU4f2ktS2olJw8wc4iZMoKFpPwcn@9mq/3PA43gvHZYzxeOZrOpxu@2HXz55djF1cZu/i8Nlwviry4vLNHv3rzts0WafJPCUaRy35f7SdaM1EDgB8gJeGFMlqDDiRArzASEu2QHIiBU8wWoE1MS7BQCTxBKMwVlFQDCCJJxgTEIaNBB8WJPUEYzDsjwgJknrCdoYVGD74I@UP "V – TIO Nexus")
The wrong tool for the job...
[Answer]
# [Perl 6](http://perl6.org/), ~~63~~ 55 bytes
~~`{($_ Z [Z] $_).kv.map(->\a,\b{b.flatmap(*[a..*]).sum -b[0;a]})}`~~
```
{($_ Z [Z] .skip).kv.map({$^b.flatmap(*[$^a..*]).sum})}
```
* `$_` is the matrix input to the anonymous function
* `.skip` is the input matrix with its first row removed
* `[Z] .skip` is the transpose of the input matrix with its first row removed; that is, the transpose without its first column
* `$_ Z [Z] .skip` zips the input matrix with its transpose-sans-first-column, producing a list `((first-row, first-column-sans-first-element), (second-row, second-column-sans-first-element), ...)`
* `.kv` prefixes each pair with its index
* `map({...})` maps over the the pairs, using a function which takes its first argument (the index) in `$^a` and its second (the row/column pair) in `$^b`
* `$^b.flatmap(*[$^a..*]).sum` strips off the first `$^a` elements of each row/column pair, then sums all the remaining elements
After some thought I realized that stripping off the first column of the transpose before zipping was equivalent to subtracting the doubly-contributing diagonal elements, as in my first solution. That let me delete that subtraction, and using each argument to the mapping function only once made the `{...$^a...$^b...}` method of passing arguments to an anonymous function more efficient than the original `-> \a, \b {...a...b...}`.
[Answer]
# Java 10, ~~248~~ ~~245~~ ~~227~~ ~~223~~ ~~219~~ 218 bytes
```
a->{int l=a.length,L=a[0].length,b[][]=new int[l][L],i,j,x=0,s;for(;++x<l|x<L;)for(i=l;i-->x;)for(j=L;j-->x;)b[i][j]=x;var r="";for(;x-->0;r=s>0?s+" "+r:r)for(s=0,i=l*L;i-->0;)s+=b[i/L][i%L]==x?a[i/L][i%L]:0;return r;}
```
-8 bytes thanks to *@ceilingcat*
[Try it online.](https://tio.run/##nVHLcptAELzrK7ZU5SoURgosT3m98g8QX3KkOKxkbC/ByLUghZTCtysNsmIRn6KLUE/vzHT3FGqv5sXjj@OmVHXNvildHSaM6arJzZPa5Oyhh4x9b4yuntnGApNmacbUTIDoJvipG9XoDXtgFZPsqOarAx6xUqpFmVfPzQslUqVOdkbrvl9W@c9@S1pmaZKRpoJa6VAtnrbGErbd3pW/27tEzHqsZSn0fL5qT7CQiShOcJ3qLC0y2Yq9MszI6fQ0oAXtCCPrlXNf21M2tc2tGZprbMG8L8kw0RGz2paY8jXJUn2TZFK29@oD3mJI3uxMxYzojqJ3@7Zbl3D7bnq/1Y/sFalZp4SGZN4j@1U3@etiu2sWb6CasrKqxcY6G0cIh7//D0HXzYZE/7PPJf/KzqijD8CvHBKTRxG5zvnjXg4FjiigmHzQ3j8chSi7KIef@jiqMXHqh@PNldI8iFqSH2NJv2BJPL5c4kFWBH1LcrErIr68ZP0QutCKekheQN4orYBc6AqJg4A3OAlG3uA1IA4G@jn5Pm50ac8ljjxA4HhDMHxEwz4Ih3xIJhePnWsv/ClZKKHRsrCPeHwXOHPGZiMKzwq6SXf8Aw)
**General explanation:**
Let's say the input array has dimensions of 4x6. The first part of the code will create a temp matrix and fills it as follows:
```
// 1. Fill the entire array with 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
// 2. Overwrite the inner part with 1 (excluding the first row & column):
0 0 0 0 0 0
0 1 1 1 1 1
0 1 1 1 1 1
0 1 1 1 1 1
// #. Etc. until we are left with this:
0 0 0 0 0 0
0 1 1 1 1 1
0 1 2 2 2 2
0 1 2 3 3 3
```
And in the second part of the code it will loop over this temp matrix, and sums all values of the input-matrix for each of the distinct numbers in the temp matrix.
**Explanation of the code:**
```
a->{                       // Method with int-matrix parameter and String return-type
  int l=a.length,          //  Amount of rows
      L=a[0].length,       //  Amount of columns
      b[][]=new int[l][L], //  New temp matrix to fill as explained above
      i,j,x=0,s;           //  Some temp integers
                           //This is the first part of the code mentioned above:
  for(;++x<l|x<L;)         //  Loop `x` over the rows or columns (whichever is larger):
    for(i=l;i-->x;)        //   Inner loop over the rows:
      for(j=L;j-->x;)      //    Inner loop over the cells of this row:
        b[i][j]=x;         //     Set the value of the current cell to `x`
                           //This is the second part of the code mentioned above:
  var r="";                //  Result-String, starting empty
  for(;x-->0               //  Loop over the unique numbers in the temp matrix:
      ;                    //     After every iteration:
       r=s>0?s+" "+r:r)    //    If the sum is larger than 0: append it
    for(s=0,               //   Reset the sum to 0
        i=l*L;i-->0;)      //   Inner loop over the cells:
      s+=b[i/L][i%L]==x?   //    If the current cell of the temp-matrix contains `x`:
          a[i/L][i%L]:0;   //     Add the input's value at this position to the sum
  return r;}               //  Return the result-String
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
Ḣ;Ḣ€SṄȧßS¿
```
A full program that prints the values
**[Try it online!](https://tio.run/nexus/jelly#@/9wxyJrIH7UtCb44c6WE8sPz3c7tP/////R0QoWOgrGOgrmOoYGSAzDWB0uhWgQy1xHwVQHpMgELG0Mk1Mw1FEwA4sagkXNkPQpGIGFgJqMdKDmg9TFxgIA)**
### How?
```
Ḣ;Ḣ€SṄȧßF¿ - Main link: list of lists a
Ḣ          - head a (pop the first row and yield it, modifying a)
  Ḣ€       - head €ach (do the same for each of the remaining rows)
 ;         - concatenate
    S      - sum (adds up the list that contains the top row and left column)
     Ṅ     - print that plus a linefeed and yield the result
         ¿ - while:
           - ... condition:
        F  -   flatten (a list of empty lists flattens to an empty list which is falsey) 
           - ... body:
       ß   -   call this link with the same arity (as a monad) i.e. Main(modified a)
      ȧ    - logical and (when the sum is non-zero gets the modified a to feed back in)
```
[Answer]
# [Python 2](https://docs.python.org/2/), 97 bytes
```
f=lambda m:[reduce(lambda x,y:x+y[i],m[i:],sum(m[i][i+1:]))for i in range(min(len(m),len(m[0])))]
```
[Try it online!](https://tio.run/nexus/python2#RYrRCsIwDEV/JY8ty8MqQ13BLwl5qK6VwFqlOti@vnZVEHLJvYdTwmV28To5iJayn5abVz@w4mbXbiNhjCSW8bVEVRuTdMay1uGRQUASZJfuXkVJavZJRY3tUV8dzeWZJb0hKKIDgum/qXVgBBoRTu0qGHdg2jr@jboqGxDOu8G6fAA "Python 2 – TIO Nexus")
[Answer]
# Pyth, ~~16~~ 15 bytes
```
.es+>b+1k>@CQkk
```
Takes a python-style array of arrays of numbers, returns an array of sums.
[Try it!](https://pyth.herokuapp.com/?code=.es%2B%3Eb%2B1k%3E%40CQkk&input=%5B%5B8%2C3%2C7%2C10%2C3%2C7%2C10%2C1%5D%2C%5B10%2C7%2C5%2C8%2C4%2C3%2C3%2C1%5D%2C%5B1%2C6%2C4%2C1%2C3%2C6%2C10%2C1%5D%2C%5B2%2C3%2C8%2C2%2C8%2C3%2C4%2C1%5D%5D&debug=0)
### Explanation
```
.es+>b+1k>@CQkk 
.e             Q  # Enumerated map over the implicit input (Q); indices k, rows b
           CQ     # Take the transpose
          @  k    # The kth column
         >    k   # cut off the first k elements
    >b+1k         # cut off the first k+1 elements of the rows, so (k,k) isn't counted twice
  s+              # add the row and column together and sum
```
[Answer]
# GNU APL 1.7, 123 bytes
Solution requires two functions: one creates a global array and the calls the second, which recursively appends the sums to that array.
```
∇f N
R←⍬
g N
R
∇
∇g N
→2+2×0∈⍴N
R←R,(+/N[1;])+(+/N[;1])-N[1;1]
g N[1↓⍳1⊃⍴N;1↓⍳2⊃⍴N]
∇
```
`∇` begins and ends the function. Both `f` and `g` take tables as arguments (essentially 2D arrays). These can be created with `X←rows cols ⍴ 1 2 3 4...`.
`R←⍬` assigns an empty vector to global variable `R`.
`g N` calls the second function with the same argument given to the first.
`⍴N` gives the dimensions of `N`; when one of the dimensions is zero, there are no more rows/columns to add up. `0∈⍴N` returns 1 if there is a zero in the dimensions. `→2+2×0∈⍴N` branches to line number 2 plus 2 times the return value of the `∈` function: if there is no zero, `∈` returns 0 and the function branches to line 2 (the next line). If there *is* a zero, `∈` returns 1 and the function branches to line 4 (the end of the function, so `return` essentially).
`/` is the reduce operator. It applies the left argument, which is an operator (`+`) to every element in the list given as the right argument. `N[1;]` gives the entire first row of the table and `N[;1]` gives the first column. `(+/N[1;])+(+/N[;1])-N[1;1]` sums the first row and column and subtracts the value in the upper left corner because it gets added both in the column sum and the row sum. `R←R,...` appends the newly calculated value to the global vector `R`.
The function then calls itself (recurse until no more rows or columns). The `⊃` pick operator obtains the specified element from the list. `1⊃⍴N` gives the number of rows, `2⊃⍴N` the number of columns. `⍳` gives all numbers from 1 to the specified number. The `↓` drop operator removes elements from the beginning of the list. If you give multiple indices when accessing elements from a table or vector (e.g. `N[1 2 3]`), APL accesses each one. Therefore, `1↓⍳1⊃⍴N` gives the indices of each row excluding the first one (`2, 3, 4, ..., N`) and `1↓⍳2⊃⍴N` gives a similar vector but for the columns. `g N[1↓⍳1⊃⍴N;1↓⍳2⊃⍴N]` calls the function again but without the first row or column.
[Answer]
# Python + NumPy, ~~75~~ 66 bytes
Input is a 2D numpy array.
```
lambda L:[sum(L[i,i:])+sum(L[i+1:,i])for i in range(min(L.shape))]
```
[**Try it online**](https://tio.run/##bZBLboQwEET3cwovIVOKsPEHkHIDbkBYEGXIWAofeZgFpydlEjYRK6uqu6tfe16X@zSqrQ/TIMbnMK/CD/MUlpdL//a@fXfDx2cn6qp5PIekbjx81abXP3GVFXyb9lMQXvhRhG78uiWDH5P69XHv5luattsc/LiIPulC6NakaUzbpunlvyuhT33XolGnlQI5HGR2PJKdfBwMCmi6@a8FSyWp7NGlKAooxASWTtNz5pbQBSfjVAlVcDJnsuOKEpIBDqqkqS2j2UhpkRvkkdlAMtpCUROGDCbCkMlA0eBmBa15NXkkFHGp@Qs7t4ouMakzaC6HZE92/kPHWQxDHLTxrP1yEmQ7i4ONs9sP)
*-9 bytes by Black Owl Kai*
[Answer]
# PHP, 76 Bytes
```
<?foreach($_GET as$k=>$v)foreach($v as$n=>$i)$r[min($k,$n)]+=$i;print_r($r);
```
[Try it online!](https://tio.run/nexus/php#s7EvyCjgUol3dw2xjY420jE0ACEjHZNYLp1oSx1zIDTSsQRxDIFMM5iMuY6hjomOBVAm1vp/Wn5RamJyhgbYFIXEYpVsWzuVMk24cBlILA8olqmpUhSdm5mnoZKto5KnGattq5JpXVCUmVcSX6ShUqRp/f8/AA "PHP – TIO Nexus")
[Answer]
## Mathematica, 116 bytes
```
l=Length;If[l@#==1||l@#[[1]]==1,Total@Flatten@#,Total/@Flatten/@Table[{#[[i]][[i;;]],#[[All,i]][[i+1;;]]},{i,l@#}]]&
```
Input form
> 
> [{{5}}], [{{1},{4}}], [{{7,2}}] or [{{....},{....}...{....}}]
> 
> 
> 
[Answer]
## Clojure, 98 bytes
```
#(vals(apply merge-with +(sorted-map)(mapcat(fn[i r](map(fn[j v]{(min i j)v})(range)r))(range)%)))
```
Iterates over the input with row and column indexes (in a very verbose manner), creates a hash-map with the minimum of `i` and `j` as the key, merges hash-maps with `+` into a sorted-map, returns values.
[Answer]
# R, 102 bytes
```
function(x)`for`(i,1:min(r<-nrow(x),k<-ncol(x)),{dput(sum(x[,1],x[1,-1]));x=matrix(x[-1,-1],r-i,k-i)})
```
returns an anonymous function; prints the results to the console, with a trailing newline. I probably need a different approach.
Iterates over the minimum of the rows and columns; prints the sum of `x[,1]` (the first column) and `x[1,-1]` the first row except for the first entry, then sets `x` to be a matrix equal to `x[-1,-1]` (i.e., `x` excluding its first row and column). Unfortunately, simply setting `x=x[-1,-1]` causes it to fail in the case of a square matrix, because when `x` is 2x2, the subsetting returns a vector rather than a matrix.
[Try it online!](https://tio.run/nexus/r#NYzBCoMwEETv@Yocd2EDbq0W2volIiiWQLAmEiMNlH67TaS9zAxvmNHNrjc7BuMsROy18z0Y4utsLPi7st69EqcpxdE9U0R6P5YtwLrNEFvijmLLpLhDvMVmHoI3MRXqYOSVoUkZ/OAemwC/eh0HC0glVWmk06m4SCm5kFnFOdshJ1FnKw8g@M@5EFXOeSTr/Qs)
[Answer]
# Java 7, ~~280~~ 276 bytes
```
import java.util.*;String d(ArrayList l){String r="";for(;l.size()>0&&((List)l.get(0)).size()>0;l.remove(0))r+=s(l)+" ";return r;}int s(List<ArrayList<Integer>>l){int s=0,L=l.size(),i=1;for(;l.get(0).size()>0;s+=l.get(0).remove(0));for(;i<L;s+=l.get(i++).remove(0));return s;}
```
[Try it here.](https://tio.run/nexus/java-openjdk#tVPLbtswELz7KwgfArJaCBL1NGQZ6LGAe8qx6IGNWYOBHgZJO0gFfbu7lGI77SU8xLpIJGc4s7Mr1R56bcmzOInwaFUTfqkWT40whnwXqhvOj1arbk929KvW4nWrjCUNG952db1cVr97TasmNOqPpGwTPTxQ6mCsCffS0oix6xGitGz7k3S7OqgNbViwJMtKS3vUHdHVqDpLzMRfXwXX3zor91JvNqg8AeoItvVFElQdX0zMijdBE9TXzZv0jFbr7e1cBcE/iDdHphrPhByOvxr1RIwVFl@nXu1Ii@HQOYUfP4lgw4Lg4yIjLalJJ1@mBWXVdPD4aqxsw/5owwNybNPRNtxRB7uWSdkwiN3/m9OXCYWZVhlDb@PIPvnaGNL7XFy4az8C8ftol5BAAXF0ecU@XhBXQAYlpEhLPDmQIzxGeO6twxFdAgdnMp0pn59AgrWvIC3Rm/O1Al76eEuw@gJjWEGMFgvgKx9WmmP5KIX4HJIMEq/eZxBj@TnwzOWNOWZeiWNnMuDYI0yPQ5rO8/th6DFwVEECDvzUXu5Fw2YhIYIUE4QYL4nu9Ld4jw8WDF7eczdffkOMfYj8WlZA/j6AcTGe/wI)
Alternative approach compared to [my previous answer](https://codegolf.stackexchange.com/a/121559/52210) with arrays, which is still shorter than this one in the end (so I kinda wasted time trying this alternative approach).
**General explanation:**
Inspiration from [*@Riley*'s amazing 05AB1E answer](https://codegolf.stackexchange.com/a/121440/52210)  
This answer uses a List and after every sum is calculated it removes the first column and first row from the List-matrix, like this:
```
// Starting matrix:
7 10 1
4 4  2
6 3  4
1 4  10
5 7  6
// After first iteration (result so far: "34 "):
4  2
3  4
4  10
7  6
// After second iteration (result so far: "34 20 "):
4
10
6
// After last iteration, result: "34 20 20 "
```
**Explanation of the code:**
```
import java.util.*;                // Required import for List and ArrayList
String d(ArrayList l){             //  Method with ArrayList parameter and String return-type
  String r="";                     //  Return-String
  for(;l.size()>0&&((List)l.get(0)).size()>0; 
                                   //  Loop as long as the list still contains anything
       l.remove(0))                //  And remove the first row after every iteration
    r+=s(l)+" ";                   //   Append the sum to the result-String
                                   //  End of loop (implicit / single-line body)
  return r;                        //  Return result-String
}                                  // End of method
int s(List<ArrayList<Integer>>l){  // Separate method with List-matrix parameter and integer return-type
  int s=0,                         //  The sum
      L=l.size(),                  //  The size of the input list
      i=1;                         //  Temp integer
  for(;l.get(0).size()>0;          //  Loop (1) over the items of the first row
    s+=l.get(0).                   //   Add the number to the sum
                remove(0)          //   And remove it from the list afterwards
  );                               //  End of loop (1)
  for(;i<L;                        //  Loop (2) over the rows
    s+=l.get(i++).                 //   Add the first number of the row to the sum
                  remove(0)        //   And remove it from the list afterwards
  );                               //  End of loop (2)
  return s;                        //  Return sum
}                                  // End of separate method
```
[Answer]
# Python, 93 bytes
Similar to mbomb007's answer, but without NumPy
```
f=lambda m:[sum(m[k][k:])+sum(list(zip(*m))[k][k+1:])for k in range(min(len(m),len(m[0])))]
```
[Answer]
# [Perl 5](https://www.perl.org/) `-MList::Util=sum -n`, 48 bytes
```
@,=eval;say sum@{shift@,},map{shift@$_}@,while@,
```
[Try it online!](https://tio.run/##NY5BCsIwFESv4sLlVJLWtKGlkAPo0lUpkkWkgbQNJioivbrxi3b1ePM/w3hzdSIlhdbctWuCfm7CbVSvMNhLVFgwav@X7XlReAzWGYWUOokCFThbwXt0hAoCEntKi1@EkoyTletXTiKR49tAp/49@2jnKaTsKHaMM@LBhljXp2hdS3NSpqcP "Perl 5 – Try It Online")
]