Re: matrix operations -- shared data vs copied
- To: mathgroup at smc.vnet.net
- Subject: [mg65933] Re: [mg65917] matrix operations -- shared data vs copied
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Mon, 24 Apr 2006 06:01:34 -0400 (EDT)
- Reply-to: hanlonr at cox.net
- Sender: owner-wri-mathgroup at wolfram.com
A=Array[a,{3,4}];
B=A;
B is a copy of A at the time the assignment is made
Clear[A]
B
{{a[1, 1], a[1, 2], a[1, 3], a[1, 4]},
{a[2, 1], a[2, 2], a[2, 3], a[2, 4]},
{a[3, 1], a[3, 2], a[3, 3], a[3, 4]}}
To Extract a column (say 2)
B[[All,2]]
{a[1, 2], a[2, 2], a[3, 2]}
Look in the Help Browser at the documentation for the add-on package
LinearAlgebra`MatrixManipulation`
Bob Hanlon
>
> From: robert.dodier at gmail.com
To: mathgroup at smc.vnet.net
> Subject: [mg65933] [mg65917] matrix operations -- shared data vs copied
>
> Hello,
>
> I'm trying to get a handle on what Mathematica does with some
> matrix operations. I wasn't able to figure it out by web or newsgroups
> search so maybe you can help.
>
> Suppose A is a matrix. Consider these operations.
>
> (1) B = A
>
> (2) myfunction[A]
>
> (3) B = (some way of extracting column 1 of A)
>
> (4) B = (some way of pasting A onto another matrix)
>
> The question of interest is whether modifying elements of A also
> modify B after operations (1), (3), and (4), and whether modifications
> of the formal argument within myfunction also modify the actual
> argument (namely A).
>
> In some math languages, B = A and myfunction[A] actually create
> copies of A, likewise row/column extraction and pasting matrices
> together. But that's not the only way to do it; I'm trying to figure
> out where Mathematica stands on this point.
>
> Thanks for any pointers or other information.
>
> Robert Dodier
>
>