Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #2780 > unrolled thread
| Started by | "McHale, Paul" <Paul.McHale@excelitas.com> |
|---|---|
| First post | 2011-05-29 11:38 +0000 |
| Last post | 2011-05-30 10:35 +0000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
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
| From | "McHale, Paul" <Paul.McHale@excelitas.com> |
|---|---|
| Date | 2011-05-29 11:38 +0000 |
| Subject | Pure functions and Select[] sequential elements of list |
| Message-ID | <irtb73$plj$1@smc.vnet.net> |
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 ;)
Best Regards,
Paul
Paul McHale | Electrical Engineer, Energetics Systems | Excelitas Technologies Corp.
Phone: +1 937.865.3004 | Fax: +1 937.865.5170 | Mobile: +1 937.371.2828
1100 Vanguard Blvd, Miamisburg, Ohio 45342-0312 USA
Paul.McHale@Excelitas.com<mailto:Paul.McHale@perkinelmer.com>
www.excelitas.com<http://www.excelitas.com>
[cid:image001.png@01CB9136.E3D96D90]
Please consider the environment before printing this e-mail.
This email message and any attachments are confidential and proprietary to Excelitas Technologies Corp. If you are not the intended recipient of this message, please inform the sender by replying to this email or sending a message to the sender and destroy the message and any attachments.
Thank you
[toc] | [next] | [standalone]
| From | Ray Koopman <koopman@sfu.ca> |
|---|---|
| Date | 2011-05-30 10:33 +0000 |
| Message-ID | <irvrpm$8gm$1@smc.vnet.net> |
| In reply to | #2780 |
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]]& ]
[toc] | [prev] | [next] | [standalone]
| From | "Chris Degnen" <degnen@cwgsy.net> |
|---|---|
| Date | 2011-05-30 10:35 +0000 |
| Message-ID | <irvrt1$8jf$1@smc.vnet.net> |
| In reply to | #2780 |
Paul McHale 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.e.
>
> mList={1,2,3,4,5,7,6,8};
> Select[mList, (#? > #??)&]
>
I would use this:
Part[mList,
Flatten[Position[#1 > #2 & @@@ Partition[mList, 2, 1], True]]]
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web