Sum in each dimension You are given a multi-dimensional array of integers. Each dimension has a fixed size (so that it would be always rectangular if it is 2D). Your program should calculate the sums in each dimension and append the sums as the new last items in that dimension.
Assume the input and output arrays are A and B, and the size of dimension i of A is ni. B would have the same number of dimensions as A and the size of dimension i would be ni+1. Bj1,j2,...,jm is the sum of Ak1,k2,...,km where:

ki = ji if ji &lt;= ni
0 &lt; ki &lt;= ni if ji = ni+1

For the input:
[[1 2 3]
 [4 5 6]]

Your program (or function) should output:
[[1 2 3 6]
 [4 5 6 15]
 [5 7 9 21]]

The input contains only the array. The total number of dimensions and the size of each dimension are not given in the input. (But you can get them from the array by your own code.) You can use any convenient list formats in your language, as long as it doesn't specify the number of dimensions or dimension sizes directly.
The input has at least 1 dimension, and has at least 1 item in the array.
This is code-golf. Shortest code wins.
Test cases
Input:
[5 2 3]
Output:
[5 2 3 10]

Input:
[[1 2 3] [4 5 6]]
Outputs:
[[1 2 3 6] [4 5 6 15] [5 7 9 21]]

Input:
[[[1] [1] [1] [0]]]
Output:
[[[1 1] [1 1] [1 1] [0 0] [3 3]] [[1 1] [1 1] [1 1] [0 0] [3 3]]]

Input:
[[[[-1]]]]
Output:
[[[[-1 -1] [-1 -1]] [[-1 -1] [-1 -1]]] [[[-1 -1] [-1 -1]] [[-1 -1] [-1 -1]]]]
Mathematica, 32 20 bytes

#/.List-&gt;({##,+##}&amp;)&amp;


Example:

In[1]:= #/.List-&gt;({##,+##}&amp;)&amp;[{{1, 2, 3}, {4, 5, 6}}]

Out[1]= {{1, 2, 3, 6}, {4, 5, 6, 15}, {5, 7, 9, 21}}


Explanation:

The full form of {{1, 2, 3}, {4, 5, 6}} is List[List[1, 2, 3], List[4, 5, 6]]. Then replace all the Lists in the expression with the function ({##,+##}&amp;).