Re: A matrix element specified by a vector?
- To: mathgroup at smc.vnet.net
- Subject: [mg123355] Re: A matrix element specified by a vector?
- From: "Oleksandr Rasputinov" <oleksandr_rasputinov at hmamail.com>
- Date: Sat, 3 Dec 2011 04:12:45 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <jbag3k$1v9$1@smc.vnet.net>
On Fri, 02 Dec 2011 12:25:24 -0000, Ralph Dratman <ralph.dratman at gmail.com> wrote: > I am wondering if there is a more compact way to express the following > idea: > > myMatrix[[ myVector[[1]], myVector[[2]] ]] = myScalar > > This keeps coming up. Did I miss the quick and easy way to do it? Of > course it looks even uglier in 3 dimensions. > > Thank you. > > Ralph Dratman > If the vector has only two elements (or only three in the 3-d case), you could use myMatrix[[ Sequence@@myVector ]] = myScalar to accomplish the same thing. I think this is about as compact as you are going to get since this operation cannot really be simplified much further. However, it doesn't look particularly verbose to me even in the form you give above. Are you finding that you need to do this for many values of myVector and myScalar at the same time? Certainly that operation could be made more compact by using e.g. MapThread.