Re: For Routine to Map Routine
- To: mathgroup at smc.vnet.net
- Subject: [mg70449] Re: For Routine to Map Routine
- From: Peter Pein <petsie at dordos.net>
- Date: Mon, 16 Oct 2006 02:36:35 -0400 (EDT)
- References: <egse9i$css$1@smc.vnet.net>
Benedetto Bongiorno schrieb:
> To All,
>
> Dimensions of ans01 is 2185850 by 5.
> I am looking to convert my For routine to the more efficient Map routine
>
> n=Length[ans01]
> fo={};
>
> For[i=1, i<n, i++,
> If[ans01[[i,1]] == ans01[[i+1,1]],
> AppendTo[fo, ans01[[1]]]];
>
> I tried
> Map[If[#[[1]] == #[[1]],#]&,ans01];
>
> But it does not work.
>
> Thank you
>
> Ben
>
>
Hi Ben,
I do not understand the use of your For-loop.
But I think it does the same as
Table[First[ans01],{Count[MapThread[Equal,Through[{Most,Rest}[ans01[[All,1]]]]],True]}]
did you mean eventually something like:
lst={1,2,3,3,4,4,4,4,5};
Flatten[Rest/@Split[lst]]
--> {3,4,4,4}
??
Peter