| Author |
Comment/Response |
Peter Pein
|
10/30/11 04:57am
Hi Igor,
since you need the sequence of indices, not the list, try these:
In[1]:= T = Array[a, {3, 3, 3}];
one possibility: convert the list to the sequence of elements:
In[2]:= test1[ix_List, t_List] := t[[Sequence @@ ix]]
In[3]:= test1[{1, 2, 3}, T]
Out[3]= a[1, 2, 3]
another one with less typing :)
let the pattern matcher do the above for you:
In[4]:= test2[{ix : (_Integer | All | _Span) ..}, t_List] :=
t[[ix]]
In[5]:= test2[{2, 1, 3}, T]
Out[5]= a[2, 1, 3]
In[6]:= test2[{3, 1}, T]
Out[6]= {a[3, 1, 1], a[3, 1, 2], a[3, 1, 3]}
In[7]:= test2[{1, 2 ;; 3, 1}, T]
Out[7]= {a[1, 2, 1], a[1, 3, 1]}
In[8]:= test2[{All, 2, 3}, T]
Out[8]= {a[1, 2, 3], a[2, 2, 3], a[3, 2, 3]}
Peter
URL: , |
|