Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #2890 > unrolled thread
| Started by | "McHale, Paul" <Paul.McHale@excelitas.com> |
|---|---|
| First post | 2011-06-02 11:16 +0000 |
| Last post | 2011-06-02 11:16 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
Re: Pure functions and Select[] sequential elements of list "McHale, Paul" <Paul.McHale@excelitas.com> - 2011-06-02 11:16 +0000
| From | "McHale, Paul" <Paul.McHale@excelitas.com> |
|---|---|
| Date | 2011-06-02 11:16 +0000 |
| Subject | Re: Pure functions and Select[] sequential elements of list |
| Message-ID | <is7rdr$rfk$1@smc.vnet.net> |
Thank you everyone for the excellent responses. My learning continues :)
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
www.excelitas.com
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
-----Original Message-----
From: DrMajorBob [mailto:btreat1@austin.rr.com]
Sent: Tuesday, May 31, 2011 7:50 AM
Subject: Re: Pure functions and Select[] sequential elements of list
Pure functions are not "function dependent"... they are argument dependent.
Select tests individual elements (hence passes ONE argument to the test
function), while Split compares adjacent PAIRS of elements (hence passes
two arguments to the test function).
It's a fundamental difference in their mission and behavior.
Bobby
On Mon, 30 May 2011 05:34:24 -0500, McHale, Paul
<Paul.McHale@excelitas.com> wrote:
> Thanks for the posts. I think this is the part I am missing.
>
> When I do this:
> mList = Range[10];
> mList[[5]] = 9;
> mList
> mList = Split[mList, (#1 > #2) &]
>
> I get:
> {1, 2, 3, 4, 9, 6, 7, 8, 9, 10}
> {{1}, {2}, {3}, {4}, {9, 6}, {7}, {8}, {9}, {10}}
>
> So it appears Split[] considers #1 = mList[[N]] and #2 =
> mList[[N+1]].
>
> However:
> mList = Range[10];
> mList[[5]] = 9;
> mList
> mList = Select[mList, (#1 > #2) &]
>
> I get errors.
> {1, 2, 3, 4, 9, 6, 7, 8, 9, 10}
> Function::slotn: "Slot number 2 in #1>#2& cannot be filled from
> (#1>#2&)[1]".>>
> ..
> General::stop: Further output of Function::slotn will be suppressed
> during this calculation. >>
>
> Looks like pure functions are treated differently depending on which
> built in function is using them. Not saying it is wrong. Just explains
> confusion. I am sure I used #N before. I just didn't realize it was
> function dependent.
>
>
>
> _______________________________________
> From: Scot T. Martin [smartin@seas.harvard.edu]
> Sent: Sunday, May 29, 2011 11:45 AM
> To: mathgroup@smc.vnet.net
> Cc: McHale, Paul
> Subject: RE: Pure functions and Select[]
> sequential elements of list
>
> I agree that this kind of functionality is not easily accessed in
> Mathematica. It seems to be a common need that requires some obscure
> formulation to get the needed effect, at least so far as I have figured
> out. Here are two examples of what I use:
>
> 1. I sometimes use Partition[...] first to get this effect:
>
> mList = Partition[{1, 2, 3, 4, 5, 7, 6, 8}, 2, 1];
> First /@ Select[mList, (#[[1]] > #[[2]]) &]
>
> 2. Pattern matching can also do the trick, though can be slow depending
> on the size of your task.
>
> mList = {1, 2, 3, 4, 5, 7, 6, 8};
> ReplaceList[mList, Rule[{___, firstValue: _, secondValue: _, ___} /;
> (firstValue> secondValue), firstValue]]
>
>
>
> ________________________________________
> From: McHale, Paul [Paul.McHale@excelitas.com]
> Sent: Sunday, May 29, 2011 07:38
> To: mathgroup@smc.vnet.net
> Subject: Pure functions and Select[] sequential
> elements of list
>
> 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
>
--
DrMajorBob@yahoo.com
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web