Re: ReplacePart position

• To: mathgroup at smc.vnet.net
• Subject: [mg52599] Re: ReplacePart position
• From: "Bas Straatman" <g15bs at morgan.ucs.mun.ca>
• Date: Fri, 3 Dec 2004 03:54:33 -0500 (EST)
• Organization: Memorial University of Newfoundland
• References: <200412011059.FAA20054@smc.vnet.net> <comgam\$5r8\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```I "solved" the problem by using MapAt in stead of ReplacePart. All I wanted
to do is increase the current value of a number of locations by 1. So
instead of ReplacePart[newes1, newes1[[Sequence@@loc]]+1, loc] I used
MapAt[(#+1)&, newes1, loc] and this works fine. I still don't understand why
Replacepart doesn't recognize the location though, every other function I
have tried recognizes the location without any trouble.

"yehuda ben-shimol" <benshimo at bgu.ac.il> wrote in message
news:comgam\$5r8\$1 at smc.vnet.net...
> 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: Re: How to solve nonlinear equations?
• Next by Date: Re: LogLog plot of NDSolve solution
• Previous by thread: Re: ReplacePart position
• Next by thread: Re: Re: canonical mathematical expression represenation?