Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

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[5]:= 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[6]:= 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][[1]]}]; 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[7]:= datalist=Range[11,3411,10];

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

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

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

Out[7]= True

and then timing data on my system

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

Out[8]= {0.000894,Null}

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

Out[9]= {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