Re: Mathematica 6.0 easier for me ... (small review)
- To: mathgroup at smc.vnet.net
- Subject: [mg76563] Re: [mg76457] Mathematica 6.0 easier for me ... (small review)
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Thu, 24 May 2007 05:57:31 -0400 (EDT)
- Reply-to: hanlonr at cox.net
lis = Flatten[Transpose[
Outer[List, Range[9], 10*Range[4]]], 1]
Since you did not provide an example of the desired output, it is ambiguous as to which pair you want to save.
Split will group the elements
sp = Split[lis, #1[[2]] == #2[[2]] &];
First /@ sp
{{1, 10}, {1, 20}, {1, 30}, {1, 40}}
Last /@ sp
{{9, 10}, {9, 20}, {9, 30}, {9, 40}}
Thread[{Most[Last /@ sp], Rest[First /@ sp]}]
{{{9, 10}, {1, 20}}, {{9, 20}, {1, 30}},
{{9, 30}, {1, 40}}}
Bob Hanlon
---- Paul at desinc.com wrote:
>
> 4. At work, I haven't had to resort to other programs because
> Mathematica wasn't the best choice. This is extremely nice. BTW,
> There's a "temporal" advantage with procedural programming that hasn't
> been apparant to me in functional or rule. Still working on it. Maybe
> someone can help. If I have
> lis={{1,10},{2,10},...{9,10},{11,20},{12,20}...{19,20}
>
> How do I use functional and/or rule to determine where the second
> number (lis[[i,2]]) jumped from 10 to 20 to 30 and save the pair.
> Assuming there was noise, I only want to store the first 10->20, then
> look for 20->30 and so on. So in time, I want my search to change as
> I progress through the list. Any input appreciated!
>