MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Summing all the elements along a dimension in a matrix


"CuppoJava" <patrickli_2001 at hotmail.com> wrote in message 
news:hc38cr$i5b$1 at smc.vnet.net...
> Hi,
> I just started using Mathematica after a year of experience with
> another system, and I have a question regarding how to handle matrices.
>
> What is the equivalent code for doing
> sum(A,3) in mathematica?
> This sums all the elements A along the third dimension.
>
> I'm having a hard time finding it in the documentation.
>
> Thanks a lot for your help
>  -Patrick
>

another system:
---------
>> A

A(:,:,1) =

     1     2
     3     4

A(:,:,2) =

     5     6
     7     8

>> size(A)

     2     2     2

>> sum(A,3)

     6     8
    10    12

Mathematica
---------------------
Dimensions[A = {{{1, 2}, {3, 4}},{{5, 6}, {7, 8}}}]
{2, 2, 2}

Total[A, 1]

  {{6, 8}, {10, 12}}

--Nasser






  • Prev by Date: presentations
  • Next by Date: Re: comparable sizes across BubbleCharts
  • Previous by thread: Re: Summing all the elements along a dimension in a matrix
  • Next by thread: Re: Summing all the elements along a dimension in a matrix