Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6891 > unrolled thread
| Started by | Ralph Dratman <ralph.dratman@gmail.com> |
|---|---|
| First post | 2011-12-02 12:25 +0000 |
| Last post | 2011-12-03 10:12 +0000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
A matrix element specified by a vector? Ralph Dratman <ralph.dratman@gmail.com> - 2011-12-02 12:25 +0000
Re: A matrix element specified by a vector? A Retey <awnl@gmx-topmail.de> - 2011-12-03 09:14 +0000
Re: A matrix element specified by a vector? "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-12-03 10:12 +0000
| From | Ralph Dratman <ralph.dratman@gmail.com> |
|---|---|
| Date | 2011-12-02 12:25 +0000 |
| Subject | A matrix element specified by a vector? |
| Message-ID | <jbag3k$1v9$1@smc.vnet.net> |
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
[toc] | [next] | [standalone]
| From | A Retey <awnl@gmx-topmail.de> |
|---|---|
| Date | 2011-12-03 09:14 +0000 |
| Message-ID | <jbcpag$biq$1@smc.vnet.net> |
| In reply to | #6891 |
Hi, > > 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. if the length of myVector matches the depth of myMatrix, this will work: myMatrix[[Sequence@@myVector]] = myScalar hth, albert
[toc] | [prev] | [next] | [standalone]
| From | "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Date | 2011-12-03 10:12 +0000 |
| Message-ID | <jbcsm0$c0r$1@smc.vnet.net> |
| In reply to | #6891 |
On Fri, 02 Dec 2011 12:25:24 -0000, Ralph Dratman <ralph.dratman@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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web