Re: List operations "in a given dimension"
- To: mathgroup at smc.vnet.net
- Subject: [mg33473] Re: List operations "in a given dimension"
- From: Thomas Burton <tburton at brahea.com>
- Date: Fri, 22 Mar 2002 04:07:03 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Hello, AFAIK, there is no core tool to do this. There may be a package tool, but the following will do it using core tools only: Map[Max,Transpose[aaa,{1,3,2}],{2}] The basic idea is to transpose the matrix so the dimension to operate on is last, and the Map the operator down to that level. Here is a generalization which I have not tested well, but it seems to work: atIndex[operator_, data_, i_Integer] := With[{n = Depth[data]-1}, With[{ii = Append[Drop[Range[n],{i}],i]}, Map[operator, Transpose[data, ii], {n-1}] ]] in terms which we can write atIndex[Max, aaa, 2] to get your result below. I hope this helps a little. Don't know much about Matlab, except to warn you about vectors. Mathematica adheres to the physical definition of a vector, whereas Matlab, as I recall, uses "row vectors" and "column vectors", which are really row matrices and column matrices. In Mathematica: vector: {a, b, c} row matrix: {{a, b, c}} column matrix: {{a}, {b}, {c}} On 3/21/02 6:51 AM, in article a7cs1f$hut$1 at smc.vnet.net, "Martin Johansson" <martin.n.johansson at emw.ericsson.se> wrote: > > Numerical example (3D): > > aaa = > {{{111, 112, 113, 114}, {121, 122, 123, 124}, {131, 132, 133, 134}}, > {{211, 212, 213, 214}, {221, 222, 223, 224}, {231, 232, 233, 234}}} > > Again, operating on aa with Max[] "w.r.t. the second > index" should yield > > {{131, 132, 133, 134}, {231, 232, 233, 234}}. Thomas E Burton 760/436-7436 353 Sanford Street, Encinitas, CA 92024-1508