       Re: More Efficient Method

• To: mathgroup at smc.vnet.net
• Subject: [mg105120] Re: More Efficient Method
• From: Bill Rowe <readnews at sbcglobal.net>
• Date: Sat, 21 Nov 2009 03:36:15 -0500 (EST)

```On 11/20/09 at 6:38 AM, blamm64 at charter.net (blamm64) wrote:

>I have a couple of functions designed to poke a single hole, and to
>poke multiple holes, in a one-level list:

>We define a function which, given the imported pressure data, finds
>the subset of that pressure data excluding the pressure data points
>between "targetL " and "targetU".

>In:= findsubset[data_?VectorQ,targetL_?NumericQ,targetU_?
>NumericQ] := Select[data,(#<=targetL || #>=targetU &)]

on my machine the following has the same result but executes faster

fs[data_?VectorQ, targetL_?NumericQ, targetU_?NumericQ] :=

Join[SparseArray[Clip[data, {First[data], targetL}, {0, 0}]] /.
SparseArray[_, _, _, {_, _, a_}] -> a,
SparseArray[Clip[data, {targetU, Last[data]}, {0, 0}]] /.
SparseArray[_, _, _, {_, _, a_}] -> a]

>This function will pluck out multiple holes in the data list.

>In:= subsets[data_?VectorQ,tarList_?ListQ]:=Module[{tmp,tmp1},
>tmp=data;
>Do[tmp1=findsubset[tmp,tarList[[i,1]],tarList[[i,2]]];tmp=tmp1,
>{i,Dimensions[tarList][]}]; tmp
>]

I the following does the same thing is simpler in my view

subs[data_?VectorQ, tarList_?ListQ] :=
Fold[fs[#1, First[#2], Last[#2]] &, data, tarList]

>The following works fine (big holes chosen not to give large
>result):

>In:= datalist=Range[11,3411,10];

>In:= targetlist={{40, 1500},{1600,3300}};

=46irst to demonstrate the my solution produces the same result

In:= subs[datalist, targetlist] == subsets[datalist, targetlist]

Out= True

and then timing data on my system

In:= Timing[subsets[datalist, targetlist];]

Out= {0.000894,Null}

In:= Timing[subs[datalist, targetlist];]

Out= {0.000175,Null}

```

• Prev by Date: Re: Setting global InputAutoReplacements
• Next by Date: Re: Undo in Mathematica
• Previous by thread: Re: More Efficient Method
• Next by thread: Re: More Efficient Method