MathGroup Archive 2007

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

Search the Archive

Re: how to transform a list in a sequence of arguments?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77330] Re: how to transform a list in a sequence of arguments?
  • From: dh <dh at metrohm.ch>
  • Date: Thu, 7 Jun 2007 03:37:24 -0400 (EDT)
  • References: <f43i7q$3lt$1@smc.vnet.net>


Hi Alessandro,

if I understand correctly, you have a matrix m and indices given as list 

{i,j,k} and you want to get m[[i,j,k]]. This can be done e.g. by:

m[[Sequence@@#]]&

hope this helps, Daniel



alexxx.magni at gmail.com wrote:

> I believed it was fairly trivial, yet I was unable to find a

> solution ...

> 

> say I have a 3d matrix,

> 

> In[64]:= s

> Dimensions[s]

> 

> Out[64]= {{{-1, 1, 1}, {-1, 1, 1}, {-1, 1, 1}}, {{1, 1, 1}, {1, 1, 1},

> {1, -1, -1}}, {{1, -1, 1}, {-1, 1, -1}, {-1, 1, -1}}}

> Out[65]= {3, 3, 3}

> 

> and I want to access&modify it in a procedure, in which the indices

> i,j,k are found sequentially: {1,1,1}, {1,1,2}, ....

> 

> How can I do it, since s[[{i,j,k}]] is not the same - of course - of

> s[[i,j,k]] ???

> 

> I finally wrote the construct:

> 

> Apply[s[[##]] &, {i,j,k}]

> 

> ant this works OK in reading, but not in writing since it reports:

> 

> s[[##]] & @@ {1,2,1} = "0"

> Set::write: Tag Apply in (s[[##1]]&)@@{1,2,1} is Protected. >>

> 

> any idea on how to make it work read/write???

> 

> P.S.

> it <does> work, for now, because I'm using this (where i0 is the

> indices list):

> s = ReplacePart[s, i0 -> - Extract[s, i0]];

> 

> but I fear that it must be much slower than a Part[] access

> 

> 

> Thank you!

> 

> Alessandro Magni

> 

> 




  • Prev by Date: Re: Version 6.0 Problems
  • Next by Date: Re: How to show the plot in Module[{}, ]?
  • Previous by thread: Re: how to transform a list in a sequence of arguments?
  • Next by thread: Segregating the elements of a list based on given lower and upper bounds