From: CuppoJava on 26 Oct 2009 00:26 Hi, I just started using Mathematica after a year of experience with Matlab, 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
From: Murray Eisenberg on 27 Oct 2009 05:57 A matrix is 2-dimensional and has no "third dimension". Are you trying to sum along the 3rd row? Along the 3rd column? Or are you talking about a higher-dimensional array? CuppoJava wrote: > 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 > -- Murray Eisenberg murray(a)math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305
From: Szabolcs Horvát on 27 Oct 2009 05:58 On 2009.10.26. 5:26, CuppoJava wrote: > 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. > This is controlled by the second argument of Total. Total[a, {3}] (depending on what you mean by 'third dimension')
From: Nasser M. Abbasi on 27 Oct 2009 05:58 "CuppoJava" <patrickli_2001(a)hotmail.com> wrote in message news:hc38cr$i5b$1(a)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
From: Sjoerd C. de Vries on 27 Oct 2009 05:58 Hi Patrick, Many ways to do this, but the easiest way will be using Total. The syntax variant you could use here is Total[A,{3}]. Perhaps you should check whether the ordering of the dimensions is the same in both systems. Cheers -- Sjoerd On Oct 26, 6:26 am, CuppoJava <patrickli_2...(a)hotmail.com> wrote: > 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
|
Next
|
Last
Pages: 1 2 Prev: How to format Superscript and Subscript for a symbol Next: Two Axis DateListPlot |