Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #2884 > unrolled thread

Re: Mapping to Create Nested Loops

Started byGregory Lypny <gregory.lypny@videotron.ca>
First post2011-06-02 11:14 +0000
Last post2011-06-02 11:14 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Mapping to Create Nested Loops Gregory Lypny <gregory.lypny@videotron.ca> - 2011-06-02 11:14 +0000

#2884 — Re: Mapping to Create Nested Loops

FromGregory Lypny <gregory.lypny@videotron.ca>
Date2011-06-02 11:14 +0000
SubjectRe: Mapping to Create Nested Loops
Message-ID<is7rbh$rd6$1@smc.vnet.net>
Hi Heike,

This is good stuff.  Thank you, Heike.  Either one will do the trick!

Regards,

Gregory


On Wed, Jun 1, 2011, at 5:01 AM, Heike Gramberg wrote:

> Do you want to gather the entries of all the arrays in 3 large lists, or do you want to generate red, blue 
> and green lists for each array separately? In the first case you could try
> 
> Cases[{myArray1, myArray2, myArray3}, {__, __, #, __, __, __}, Infinity] & /@ {red, blue, green}
> 
> which searches all levels of {myArray1,...,myArray3} for the given pattern. In the second case you could 
> do something like
> 
> Function[{lst}, Cases[{lst}, {__, __, #, __, __, __}] & /@ {red, blue, green}] /@ {myArray1, myArray2, myArray3}
> 
> Then %[[1]] would give you the red, blue, green lists for myArray1, etc.
> 
> 
> Heike.
> 
> 
> On 1 Jun 2011, at 09:32, Gregory Lypny 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. 
>> 
>> 
>> Regards,
>> 
>> Gregory

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web