MathGroup Archive 2009

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

Search the Archive

Re: Manipulating list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101577] Re: Manipulating list
  • From: earthnut at web.de (Bastian Erdnuess)
  • Date: Fri, 10 Jul 2009 06:47:45 -0400 (EDT)
  • References: <200907081113.HAA12448@smc.vnet.net> <h340q8$gpk$1@smc.vnet.net>

Leonid Shifrin <lshifr at gmail.com> wrote:

> MapThread[Prepend, {list2, list1[[All, 3]]}]
> 
> or
> 
> Flatten /@ Transpose[{list1[[All, 3]], list2}]
> 
> or
> 
> Module[{copy = list1}, copy[[All, {1, 2}]] = list2; RotateRight[copy, {0,
> 1}]]]
> 
> will do what you want. There are also many other ways of course. Note
> that on (very) large lists, the last solution is by far the most efficient
> of those
> I listed (20 - 25 x faster on lists of length 100000 according to my tests).

Even faster:

  Transpose[ Prepend[ Transpose[ list2 ], list1[[ All, 3 ]] ] ]

Bastian


  • Prev by Date: Re: Is it possible to impose a condition on an iterator
  • Next by Date: Symbolic summation
  • Previous by thread: Re: Manipulating list
  • Next by thread: Re: Manipulating list