Re: [Q] Mathematica, how to write a[[2,3]] having {2,3}

• To: mathgroup at smc.vnet.net
• Subject: [mg9289] Re: [mg9233] [Q] Mathematica, how to write a[[2,3]] having {2,3}
• From: Allan Hayes <hay at haystack.demon.co.uk>
• Date: Mon, 27 Oct 1997 02:47:00 -0500
• Sender: owner-wri-mathgroup at wolfram.com

```eds at gravi.physik.uni-jena.de (E. Schmidt) Subject: [mg9289] [mg9233] [Q]
Mathematica, how to write a[[2,3]] having {2,3}

> I want Mathematica to do is to read/write the element
> of the multidimensional array (List of List of...)
> with the indices are given in a List, e.g.
>
>In[]
> a={{11,12,13},{21,22,23,24,25}};
> ind12={1,2};
> NewValue=1000;
> SetElem[a,ind12,NewValue]
> a
>
>Out[]
> {{11,1000,13},{21,22,23,24,25}}

Eduard:

a = {{11,12,13},{21,22,23,24,25}};
ind12={1,2};
NewValue=1000;
a[[Sequence@@{1,2}]] = NewValue;
a

{{11, 1000, 13}, {21, 22, 23, 24, 25}}

This is an efficient process, but it requires the matrix to be   given a
name and we have to use this name to get the new value. The   following
will work on the name or directly on the (unnamed) matrix,   and ouputs
the modified matrix.

ReplacePart[a,2 NewValue,ind12]

{{11, 2000, 13}, {21, 22, 23, 24, 25}}

ReplacePart[{{11,12,13},{21,22,23,24,25}},3 NewValue,ind12]
{{11, 3000, 13}, {21, 22, 23, 24, 25}}

However it will not change the value of a;

a
{{11, 1000, 13}, {21, 22, 23, 24, 25}}

to do this or assign a name we could simply do something like

a = ReplacePart[a,2 NewValue,ind12]

Allan Hayes
hay at haystack.demon.co.uk
http://www.haystack.demon.co.uk/training.html voice:+44 (0)116 2714198
fax: +44 (0)116 2718642
Leicester,  UK

```

• Prev by Date: Line Breaking/Word Wrapping in Mathematica?
• Next by Date: Re: Not a machine-size real number?
• Previous by thread: [Q] Mathematica, how to write a[[2,3]] having {2,3}
• Next by thread: Which version for symbolic calculation, student or full ?