MathGroup Archive 1997

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

Search the Archive

Re: ReplacePart

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9702] Re: [mg9656] ReplacePart
  • From: David Withoff <withoff>
  • Date: Fri, 21 Nov 1997 01:31:51 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

> Under "Help" in Mathematica 3.0.1 it says ReplacePart[expr, new, pos,
> npos] replaces parts at positions pos in expr by parts at positions
> npos in new.
>
> When I try
> ReplacePart[{1,2,3,4,5},{7,8},{{2},{3}}, {1}] I get
> {1,7,7,4,5}
>
> But when I try to put parts 1 and 2 in parts 2 and 3 it fails
> ReplacePart[{1,2,3,4,5}, {7,8}, {{2},{3}}, {1,2}] Or
> ReplacePart[{1,2,3,4,5}, {7,8}, {{2},{3}}, {{1},{2}}] I get
> "Part specification {7,8}[[1,2]]  (or {7,8}[[{1},{2}]] ) is longer than
> depth of object"
>
> So it appears I have to use Fold to replace several parts of expr1 with
> corresponding parts or expr2.
>
> What do you think?

ReplacePart can put one element in several different places, but it
won't (at least not currently) put several different elements in
several different places.  Something like

Fold[ReplacePart[#1, #2[[1]], #2[[2]]] &, {1,2,3,4,5}, {{7, 2}, {8, 3}}]

will work fine for putting different elements in different places.

Dave Withoff
Wolfram Research


  • Prev by Date: Re: programs
  • Next by Date: Re: How to remove an option?
  • Previous by thread: ReplacePart
  • Next by thread: Re: [mg9568}Color Printing -- Thanks