MathGroup Archive 2006

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

Search the Archive

Re: For Routine to Map Routine


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


  • Prev by Date: pretty output with HoldForm
  • Next by Date: Re: notebook window position
  • Previous by thread: For Routine to Map Routine
  • Next by thread: Re: For Routine to Map Routine