Re: reading different locations of a matrix specified
- To: mathgroup at smc.vnet.net
- Subject: [mg113918] Re: reading different locations of a matrix specified
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Thu, 18 Nov 2010 07:04:08 -0500 (EST)
- References: <201011161004.FAA05711@smc.vnet.net> <Pine.LNX.4.63.1011160429540.6974@wopr.wolfram.com> <4CE26195.7080304@12000.org> <Pine.LNX.4.63.1011160456580.6974@wopr.wolfram.com> <ic0ar9$6pm$1@smc.vnet.net>
Hi,
> I was using
>
> ---------------------------
> A={{1,2,3},{4,5,6},{7,8,9}};
> pos={{1,1},{3,3}};
>
> (A[[ Sequence@@ #]]=0) & / @ pos; (* UPDATE *)
>
> A
> Out[192]= {{0,2,3},{4,5,6},{7,8,0}}
> --------------------------
>
> and this works ok. But from your reponses, I started looking
> again at the documenation to see if I can find another
> command like Extract, but works to do a write, not just read,
> and then I found it:
>
> ------------------------------------
> A={{1,2,3},{4,5,6},{7,8,9}};
> pos={{1,1},{3,3}};
>
> ReplacePart[A,pos->0] (* UPDATE *)
>
> Out[207]= {{0,2,3},{4,5,6},{7,8,0}}
> ------------------------------------
>
> So, I am very happy now. With Extract[] to read, with ReplacePart[]
> to write, I have all the tools I needed now to make my code
> look better. Good bye Sequence@@, it was nice knowing you ;)
I think you should be aware that the memory consumption of the two might
be very different for large matrices: ReplacePart will make a copy while
the Part+Sequence will change the matrix in place. It might make a
difference depending on what you do (you might want to look at
MemoryInUse and MaxMemoryUsed to see what happens)...
hth,
albert
- References:
- Re: reading different locations of a matrix specified by indices
- From: "Nasser M. Abbasi" <nma@12000.org>
- Re: reading different locations of a matrix specified by indices