Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2011

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

Search the Archive

Re: Mapping to Create Nested Loops

  • To: mathgroup at
  • Subject: [mg119395] Re: Mapping to Create Nested Loops
  • From: Bob Hanlon <hanlonr at>
  • Date: Wed, 1 Jun 2011 07:27:29 -0400 (EDT)
  • Reply-to: hanlonr at

GatherBy[myArray, #[[3]] &]

GatherBy[#, #[[3]] &] & /@ myListOfArrays

Bob Hanlon

---- Gregory Lypny <gregory.lypny at> wrote: 

Hello everyone,

I'm trying to learn how to use pure functions and mapping to create what amounts to nested loops. 

Suppose I have a 50 x 6 array called myArray.  The third element of each row is the word red, blue, or green.  If I wanted to break down the array into three according to the value of the third element, I could do this:

Cases[myArray, {__, __, #, __, __, __}] & /@ {red, blue, green}

But what if I needed to do this for more than one array?  Suppose I had three 50 x 6 arrays as

myListOfArrays = {myArray1, myArray2, myArray3} or perhaps the arrays might be imported from files. 



  • Prev by Date: Re: what is the command to output superfunction?
  • Next by Date: Re: FixedPoint[Cos, 1.0]
  • Previous by thread: Re: Mapping to Create Nested Loops
  • Next by thread: Re: Mapping to Create Nested Loops