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

• To: mathgroup at smc.vnet.net
• Subject: [mg104309] Re: Summing all the elements along a dimension in a matrix
• From: "Nasser M. Abbasi" <nma at 12000.org>
• Date: Tue, 27 Oct 2009 04:58:32 -0500 (EST)
• References: <hc38cr\$i5b\$1@smc.vnet.net>

```"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