[Date Index]
[Thread Index]
[Author Index]
Re: patterns
*To*: mathgroup at smc.vnet.net
*Subject*: [mg31190] Re: [mg31124] patterns
*From*: Tomas Garza <tgarza01 at prodigy.net.mx>
*Date*: Tue, 16 Oct 2001 01:19:21 -0400 (EDT)
*References*: <200110120736.DAA28433@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
I'm not sure that your function works always, as the following example
shows:
In[1]:=
t={{0, 1, 1},{1, 1, 0}};
In[2]:=
f[0.01, t]
Out[2]=
{{1, 1}}
Since you have two consecutive elements satisfying the condition in the
first row, and two more in the second row, the answer here should be {{1,
1},{1, 1}}, doesn't it? I suggest you use a more general form of Partition,
namely Partition[Flatten[matrix], 2, 1] instead of
Partition[Flatten[matrix], 2] (see Help browser unde Partition). But then,
it is not clear to me whether you want to work on the original matrix or
not, for using Flatten actually destroys its structure. I.e., when you say
"selecting consecutive elements of a list that satisfy a particular
condition", bear in mind that the elements of your original list are
sublists, not numbers. So, if you mean that you want to use your selector on
each sublist, then you must keep the original structure untouched. Then I'd
suggest modifying your function f to look something like
In[3]:=
Clear[g];g[x_,matrix_]:=
Module[{t,selector},(*Flatten and group number in pairs*)t=
Partition[#, 2,1]&/@matrix;
(*Selector:returns true if all in list>x*)selector[xx_,list_]:=
Apply[And,Map[(#>xx)&,list]];
(*select*)Select[#,selector[x,#]&]&/@t]
which now, applied to the above t, gives the right answer (preserving the
structure of the original matrix):
In[4]:=
g[0.01,t]
Out[4]=
{{{1,1}},{{1,1}}}
Before atempting to look at your other questions, I think you should provide
a more precise definition of the problem.
Tomas Garza
Mexico City
----- Original Message -----
From: <Yannis.Paraskevopoulos at ubsw.com>
To: mathgroup at smc.vnet.net
Subject: [mg31190] [mg31124] patterns
> Hi,
>
> I have built the following function for selecting consecutive elements
> of a list that do satisfy a particular condition. Here it is:
>
>
> f[x_, matrix_] := Module[{t, selector},
> (* Flatten and group number in pairs *)
> t = Partition[Flatten[matrix], 2];
> (* Selector : returns true if all in list > x *)
> selector[xx_, list_] := Apply[And, Map[(# > xx) &, list]];
> (* select *)
> Select[t, selector[x, #] &]]
>
>
> t = Table[Table[Random[], {4}], {12}];
>
> f[0.01,t]
>
> {{0.301739,0.837578},{0.710472,0.373638},{0.950287,0.828919},{0.327263,
> 0.861149},{0.734775,0.491342},{0.623224,0.365866},{0.962033,
> 0.549466},{0.0602337,0.0313664},{0.293098,0.277972},{0.0841844,
> 0.550993},{0.0538037,0.157458},{0.990937,0.167571},{0.752064,
> 0.31988},{0.280465,0.793933},{0.801777,0.490962},{0.953202,
> 0.932784},{0.0670017,0.99962},{0.329978,0.566918},{0.104969,
> 0.450153},{0.269745,0.535552},{0.811871,0.172181},{0.18556,
> 0.984558},{0.758067,0.0147228},{0.194623,0.816987}}
>
> seems to work. My question is how one could modify the function so :
> 1) we pick the first set of consecutive numbers that satisfy the
> condition and 2) from any partition of 10 you check the first 5 who
> satisfy the condition (again continuous) and then go to the next row
> of the initial matrix.
>
> Do you know any good reference with lots of examples for conditions and
> patterns with lists and matrices?
>
>
> Thank you very much in advance.
>
> yannis
>
>
>
>
>
> Visit our website at http://www.ubswarburg.com
>
> This message contains confidential information and is intended only
> for the individual named. If you are not the named addressee you
> should not disseminate, distribute or copy this e-mail. Please
> notify the sender immediately by e-mail if you have received this
> e-mail by mistake and delete this e-mail from your system.
>
> E-mail transmission cannot be guaranteed to be secure or error-free
> as information could be intercepted, corrupted, lost, destroyed,
> arrive late or incomplete, or contain viruses. The sender therefore
> does not accept liability for any errors or omissions in the contents
> of this message which arise as a result of e-mail transmission. If
> verification is required please request a hard-copy version. This
> message is provided for informational purposes and should not be
> construed as a solicitation or offer to buy or sell any securities or
> related financial instruments.
>
>
**References**:
**patterns**
*From:* Yannis.Paraskevopoulos@ubsw.com
Prev by Date:
**Re: patterns**
Next by Date:
**webMathematica**
Previous by thread:
**patterns**
Next by thread:
**Re: patterns**
| |