Message Boards Message Boards

0
|
3185 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Expanding a list

Posted 10 years ago

Hello, can somebody help me :

Given a list of Integers, say v={5, 4, 0, 6} and a list of allowed positions, say pos={1, 3} (but it might be {1, 2, 3} or {2} or ...), I need an automatic expansion of v equivalent to, say : Table[{i, 4, j, 6},{i,2},{j,2}] where i and j occupy the positions defined by pos. Please remember that pos migth be {1, 2, 3} so that i,j and k would be needed in that case. Thanks for the help ! André

POSTED BY: Andre Hautot
2 Replies

An attempt:

v = {5, 4, 0, 6};
pos = {1, 3};
vars = Table[i[k], {k, Length[pos]}];
Table[Evaluate@ReplacePart[v, Thread[pos -> vars]], 
 Evaluate[Sequence @@ Map[{#, 2} &, vars]]]
POSTED BY: Gianluca Gorni
Posted 10 years ago

Thanks a lot, it fixes the question neatly !

POSTED BY: Andre Hautot
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract