Re: Table of tables
- To: mathgroup at smc.vnet.net
- Subject: [mg113292] Re: Table of tables
- From: Sseziwa Mukasa <mukasa at jeol.com>
- Date: Fri, 22 Oct 2010 01:36:23 -0400 (EDT)
On Oct 21, 2010, at 7:01 AM, Luiz Melo wrote: > > Thanks Sebastian and Valeri for the help. > > I'm actually looking for a function that operates only on the third row of each > column-matrix terms(which happen to be complex in the example I gave), but > leaves the other terms intact. Consider a different example: > > Let > t == {{{-1, -1, -2}, {-1, -1, -3}}, {{-1, -1, -4}, {-1, -1, -5}}}; > > how can I get > > {{{-1, -1, 2}, {-1, -1, 3}}, {{-1, -1, 4}, {-1, -1, 5}}}; > > that is, in this case, I need a function that takes the Abs[] of the 3rd row of > each sub-matrix and leaves the other terms intact. MapAt[Abs, t, Flatten[Table[{i, j, 3}, {i, First[Dimensions[t]]}, {j, Dimensions[t][[2]]}], 1]] More generally mapAtColumn[t_,column_,f_]:==Module[{d},MapAt[f,t,Flatten[Table[Append[Table[d[i],{i,ArrayDepth[t]-1}],column],Evaluate[Sequence@@Table[{d[i], Dimensions[t][[i]]},{i,ArrayDepth[t]-1}]]],ArrayDepth[t-2]]]] will map f onto the last position column of a multidimensional array t. This can be further generalized to map onto a single value of a particular dimension and all other dimensional values. Regards, Ssezi >> Hi Luiz! >> >> Luiz Melo wrote: >>> Given >>> >>> t == {{{-1, -1, -2+2I}, {-1, -1, 3-I}}, {{-1, -1, 4+I}, {-1, -1, -5-5I}}}; >>> >>> how can I extract the imaginary part of the complex elements to obtain >>> >>> {{{-1, -1, 2}, {-1, -1, -1}}, {{-1, -1, 1}, {-1, -1, -5}}}; >> >> What about: >> >> Function[{e}, If[Im[e] ==== 0, e, Im[e]], Listable][t] >> >> There seems to be no ComplexQ therefore I test with "Im[e] ==== 0" if it >> is not a complex number. >> >> Cheers, >> >> Sebastian >> > > > -- > >