Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #16680

Re: Mapping tag-value lists to a third

From Ray Koopman <koopman@sfu.ca>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Mapping tag-value lists to a third
Date 2014-03-22 04:08 +0000
Message-ID <lgj2c7$lcc$1@smc.vnet.net> (permalink)
Organization Time-Warner Telecom

Show all headers | View raw


----- carlos felippa%colorado edu <carlos.felippa%colorado.edu@gtempaccount.com> wrote:
> 
> Thanks to all who replied.  For now I have implemented it as
> 
> tagval=If [$VersionNumber>=5.1,Pick[val,tag,1],val*tag/. 0:>Sequence[]];
> 
> For big lists, Pick is slightly faster. Eg, for 10^7 length, on a MacPro:
> 
>      Pick 1.45 sec    Sequence: 1.72 sec
> 
> The reason for $VersionNumber is that Pick appeared in 5.1. Some
> users of my Mathematica codes are colleagues living overseas who run
> version 4 on old computers.  

For v4 users,  

  val*tag/. 0:> Sequence[]  

requires that val have no zeros. However,

  val[[ tag*Range@Length@tag/. 0:>Sequence[] ]]

has no such condition and may be faster when val is real.

For v5+ users,

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

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

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar


Thread

Re: Mapping tag-value lists to a third Ray Koopman <koopman@sfu.ca> - 2014-03-22 04:08 +0000

csiph-web