Re: Modifying an entry in array specified by a list of arbitrary length
- To: mathgroup at smc.vnet.net
- Subject: [mg127182] Re: Modifying an entry in array specified by a list of arbitrary length
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Thu, 5 Jul 2012 06:15:02 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
x = Array[a, {4, 3, 5}];
i = {1, 2, 3};
Element to be modified
x[[Sequence @@ i]]
a[1, 2, 3]
Change element
x[[Sequence @@ i]] += 1
1 + a[1, 2, 3]
Verifying that array was modified
x[[Sequence @@ i]]
1 + a[1, 2, 3]
Bob Hanlon
On Wed, Jul 4, 2012 at 3:32 AM, <samid.hoda at gmail.com> wrote:
> Hi,
>
> I want to edit an element whose position is specified by an arbitrary list that is a result of a computation (the list is not of fixed length). Something like
>
> i = {1,2,3}
> Extract[X,i]+=1
>
> except that Extract passes X by value instead of by reference. Anyone have any ideas?
>
> Thanks,
> Sam
>