MathGroup Archive 2004

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

Search the Archive

Re: ReplacePart position

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52563] Re: [mg52551] ReplacePart position
  • From: yehuda ben-shimol <benshimo at bgu.ac.il>
  • Date: Thu, 2 Dec 2004 02:21:15 -0500 (EST)
  • References: <200412011059.FAA20054@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

You  do not have any syntax error. I checked your code  and it is 
functional.
newes1 = Table[0, {11}, {4}, {1}, {2}, {3}]; (* generate an artificial 
list to reference to *)
newes1[[11, 4, 1, 2, 3]] = 18; (* assign a value to the required place *);
Part[newes1, 11, 4, 1, 2, 3]
18 (* this notation is working *)
Position[newes1, 18]
{{11, 4, 1, 2, 3}} (* working *)
ReplacePart[newes1, 19, {11, 4, 1, 2, 3}] (* 19 appears as the last 
element *)
{{{{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {0, 0,
          0}}}, {{{0, 0, 0}, {0, 0, 0}}}}, {{{{0, 0, 0}, {0, 0, 0}}}, 
{{{0, 0,
           0}, {0, 0, 0}}}, {{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {
          0, 0, 0}}}}, {{{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {0,
           0, 0}}}, {{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {0,
           0, 0}}}}, {{{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {
          0, 0, 0}}}, {{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {
          0, 0, 0}}}}, {{{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {0,
           0, 0}}}, {{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {0,
           0, 0}}}}, {{{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {
          0, 0, 0}}}, {{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {
          0, 0, 0}}}}, {{{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {0,
           0, 0}}}, {{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {0,
           0, 0}}}}, {{{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {
          0, 0, 0}}}, {{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {
          0, 0, 0}}}}, {{{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {0,
           0, 0}}}, {{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {0,
           0, 0}}}}, {{{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {
          0, 0, 0}}}, {{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0,
    0}, {0, 0, 0}}}}, {{{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0,
   0}, {0, 0, 0}}}, {{{0, 0, 0}, {0, 0, 0}}}, {{{0, 0, 0}, {0, 0, 19}}}}}

Also working  the same
ReplacePart[newes1, 19, {{11, 4, 1, 2, 3}}]

Better check the dimensions of your list by Dimensions[news1] to see if 
there is another problem
yehuda.


Bas Straatman wrote:

>Hello--
>
>Half way through my simulations I run into the following problem. The model
>generates a list and when I try to replace parts of that list it does fine
>in most cases. However, there is a position in the list that does not exist
>according to ReplacePart. For example:
>
>newes1[[11, 4, 1, 2, 3]]
>
>18
>
>Part[newes1, 11, 4, 1, 2, 3]
>
>18
>
>Position[newes1, 18]
>
>{{11, 4, 1, 2, 3}}
>
>ReplacePart[newes1, 19, {11, 4, 1, 2, 3}]
>
>ReplacePart :: partw :  Part {11, 4, 1, 2, 3} of ..... does not exist.
>
>
>newes1 is the list of lists (5 levels) mentioned above. I can understand it
>would be helpful to actually have that list here, but it is too long to
>include. Furthermore it wouldn't help, because when I close the Kernel and
>define the list exactly as newes1 is at this moment, and replace the part as
>above it works fine. I can even copy the part of the output after the error
>message and execute it and no problem, the part is there. FullForm doesn't
>give me any new insights, the list is there and nothing seems to be wrong.
>Same for Trace, the whole list is there, but ReplacePart cannot replace the
>element at above mentioned position.
>
>Strangely enough the following does work:
>
>Part[newes1, 11, 4, 1, 2, 3] = 19
>
>19
>
>Part[newes1, 11, 4, 1, 2, 3]
>
>19
>
>Does anyone know where I can find an explanation for this? Thanks.
>
>Bas Straatman
>
>
>  
>


  • Prev by Date: Re: Getting at an AutoGenerated Package
  • Next by Date: Re: Inserting user material in the HelpBrowser
  • Previous by thread: ReplacePart position
  • Next by thread: Re: ReplacePart position