MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: A matrix element specified by a vector?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123359] Re: A matrix element specified by a vector?
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Sat, 3 Dec 2011 04:13:28 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201112021221.HAA01882@smc.vnet.net>

n = RandomInteger[{2, 6}]

4

myVector = RandomSample[Range[n]]

{4, 3, 2, 1}

myMatrix = Array[m, Table[n, {n}]];

myMatrix[[Sequence @@ myVector]] = myScalar;

Flatten[Position[myMatrix, myScalar]] == myVector

True


Bob Hanlon


On Fri, Dec 2, 2011 at 7:21 AM, 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



  • Prev by Date: Re: A matrix element specified by a vector?
  • Next by Date: Re: A matrix element specified by a vector?
  • Previous by thread: Re: A matrix element specified by a vector?
  • Next by thread: Re: A matrix element specified by a vector?