2.54 sum all columns in a matrix
Given the folowing 2D matrix \(A\) find the sum of each column
\(\begin {pmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end {pmatrix}\)
| Mathematica
In[3]:= mat={{1,2,3},
{4,5,6},
{7,8,9}}
Total[mat,{1}]
Out[4]= {12,15,18}
|
Matlab
A=[1 2 3;4 5 6;7 8 9];
sum(A,1)
ans =
12 15 18
|
| Maple
`add`~([LinearAlgebra:-Column(A,[1..-1])])
# [12, 15, 18]
| |