Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #2803

Re: Pure functions and Select[] sequential elements of list

From Ray Koopman <koopman@sfu.ca>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Pure functions and Select[] sequential elements of list
Date 2011-05-30 10:33 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <irvrpm$8gm$1@smc.vnet.net> (permalink)
References <irtb73$plj$1@smc.vnet.net>

Show all headers | View raw


On May 29, 4:38 am, "McHale, Paul" <Paul.McH...@excelitas.com> wrote:
> Hi,
>
> Does anyone know of a way to use a pure function to access current
> and next element of list with uses like Select[]?  I know I might
> be dazed and confused, but I thought there was a way.  I.e.
>
> mList={1,2,3,4,5,7,6,8};
> Select[mList, (#? > #??)&]
>
> Where #? Is element N and #?? Is element N+1.  I would expect
> the previous code (assuming N?, N?? were valid) to return 7.
>
> Maybe there is no way to do this with a pure function.  I know
> there are many other ways.  This would be one more way to not
> require a looping construct to resolve this.  If someone knows
> of straightforward ways other than Table[] or For[], Do[]...
> looping contructs, I would appreciate it the general knowledge.
> I constantly struggle against my C language beginning ;)

There are many ways to do this. Probably the simplest (but
not the fastest) is to Partition the list using an offset:

First /@ Select[ Partition[mList,2,1], #[[1]] > #[[2]]& ]

Back to comp.soft-sys.math.mathematica | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Pure functions and Select[] sequential elements of list "McHale, Paul" <Paul.McHale@excelitas.com> - 2011-05-29 11:38 +0000
  Re: Pure functions and Select[] sequential elements of list Ray Koopman <koopman@sfu.ca> - 2011-05-30 10:33 +0000
  Re: Pure functions and Select[] sequential elements of list "Chris Degnen" <degnen@cwgsy.net> - 2011-05-30 10:35 +0000

csiph-web