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: [mg77242] Re: how to transform a list in a sequence of arguments?
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Wed, 6 Jun 2007 06:52:02 -0400 (EDT)
  • Organization: Uni Leipzig
  • References: <f43i7q$3lt$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de

Hi,

you mean

   Part[s,Sequence @@ {i,j,k}]

Regards
   Jens
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: $CellContext
  • Next by Date: Re: Convert to new "Code" style from a now-redundant custom style
  • Previous by thread: how to transform a list in a sequence of arguments?
  • Next by thread: Re: how to transform a list in a sequence of arguments?