MathGroup Archive 2014

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

Search the Archive

Re: Mapping tag-value lists to a third

  • To: mathgroup at smc.vnet.net
  • Subject: [mg132467] Re: Mapping tag-value lists to a third
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sun, 23 Mar 2014 05:00:18 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net

On 3/22/14 at 12:06 AM, koopman at sfu.ca (Ray Koopman) wrote:

>For v5+ users,

>val[[ SparseArray[tag] /. SparseArray[_,_,_,d_] :> Flatten@d[[2,2]]
>]]

>may be faster than Pick[val,tag,1].

For what it is worth

In[1]:= n = 10^7;
val = RandomReal[1, n];
tag = RandomInteger[1, n];

In[4]:= Timing[c = Pick[val, tag, 1];]

Out[4]= {0.137875,Null}

In[5]:= Timing[
 b = val[[SparseArray[tag] /.
      SparseArray[_, _, _, d_] :> Flatten@d[[2, 2]]]];]

Out[5]= {0.255513,Null}

In[6]:= b == c

Out[6]= True

In[7]:= $Version

Out[7]= 9.0 for Mac OS X x86 (64-bit) (January 24, 2013)




  • Prev by Date: Re: Problems with Solve
  • Next by Date: Re: Problems with Solve
  • Previous by thread: Re: Mapping tag-value lists to a third
  • Next by thread: Re: Mapping tag-value lists to a third