Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

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


  • 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