Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #2881 > unrolled thread
| Started by | Bob Hanlon <hanlonr@cox.net> |
|---|---|
| First post | 2011-06-01 11:27 +0000 |
| Last post | 2011-06-02 11:16 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Re: Mapping to Create Nested Loops Bob Hanlon <hanlonr@cox.net> - 2011-06-01 11:27 +0000
Re: Mapping to Create Nested Loops Szabolcs Horvát <szhorvat@gmail.com> - 2011-06-02 11:16 +0000
| From | Bob Hanlon <hanlonr@cox.net> |
|---|---|
| Date | 2011-06-01 11:27 +0000 |
| Subject | Re: Mapping to Create Nested Loops |
| Message-ID | <is57n9$dgk$1@smc.vnet.net> |
GatherBy[myArray, #[[3]] &]
GatherBy[#, #[[3]] &] & /@ myListOfArrays
Bob Hanlon
---- Gregory Lypny <gregory.lypny@videotron.ca> 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] | [next] | [standalone]
| From | Szabolcs Horvát <szhorvat@gmail.com> |
|---|---|
| Date | 2011-06-02 11:16 +0000 |
| Message-ID | <is7rdh$rf9$1@smc.vnet.net> |
| In reply to | #2881 |
On 2011.06.01. 13:27, Bob Hanlon wrote: > GatherBy[myArray, #[[3]]&] > > GatherBy[#, #[[3]]&]& /@ myListOfArrays > > Is this kind of use of nested functions with # guaranteed to be safe (let's disregard readability concerns for now)? It appears that # indeed is always the argument of the innermost function, but I couldn't find this stated in the docs. Instead, it's suggested in the docs (page for Slot) to use named arguments with nested functions (but those aren't without name-conflict / localization issues either)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web