Combine `Table` with `Riffle`
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I have table of function f[x,a]
. For the sake of easy reproduction, let's limit it to a few entries - the original is over 1000 x 1000
:
actualtable=Table[f[x, a], x, 0, 4, a, 1, 4]
*f[0, 1], f[0, 2], f[0, 3], f[0, 4], f[1, 1], f[1, 2], f[1, 3],
f[1, 4], f[2, 1], f[2, 2], f[2, 3], f[2, 4], f[3, 1], f[3, 2],
f[3, 3], f[3, 4], f[4, 1], f[4, 2], f[4, 3], f[4, 4]*
I want to find a way to interject a value m
between each list item, to create
desiredtable=f[0, 1], m, f[0, 2], m, f[0, 3], m, f[0, 4], f[1, 1], m, f[1, 2],
m, f[1, 3], m, f[1, 4], f[2, 1], m, f[2, 2], m, f[2, 3], m,
f[2, 4], f[3, 1], m, f[3, 2], m, f[3, 3], m, f[3, 4], f[4, 1],
m, f[4, 2], m, f[4, 3], m, f[4, 4]
I tried using Riffle
in conjunction with Table
, but it only injects m
in between lines, rather than in between individual entries.
Obviously, with a tiny table like this, it's easy, I can just type in the m
s, or type the Riffle
command once for each line of the output.
But for a very big table, how do I do it?
list-manipulation table
add a comment |Â
up vote
3
down vote
favorite
I have table of function f[x,a]
. For the sake of easy reproduction, let's limit it to a few entries - the original is over 1000 x 1000
:
actualtable=Table[f[x, a], x, 0, 4, a, 1, 4]
*f[0, 1], f[0, 2], f[0, 3], f[0, 4], f[1, 1], f[1, 2], f[1, 3],
f[1, 4], f[2, 1], f[2, 2], f[2, 3], f[2, 4], f[3, 1], f[3, 2],
f[3, 3], f[3, 4], f[4, 1], f[4, 2], f[4, 3], f[4, 4]*
I want to find a way to interject a value m
between each list item, to create
desiredtable=f[0, 1], m, f[0, 2], m, f[0, 3], m, f[0, 4], f[1, 1], m, f[1, 2],
m, f[1, 3], m, f[1, 4], f[2, 1], m, f[2, 2], m, f[2, 3], m,
f[2, 4], f[3, 1], m, f[3, 2], m, f[3, 3], m, f[3, 4], f[4, 1],
m, f[4, 2], m, f[4, 3], m, f[4, 4]
I tried using Riffle
in conjunction with Table
, but it only injects m
in between lines, rather than in between individual entries.
Obviously, with a tiny table like this, it's easy, I can just type in the m
s, or type the Riffle
command once for each line of the output.
But for a very big table, how do I do it?
list-manipulation table
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I have table of function f[x,a]
. For the sake of easy reproduction, let's limit it to a few entries - the original is over 1000 x 1000
:
actualtable=Table[f[x, a], x, 0, 4, a, 1, 4]
*f[0, 1], f[0, 2], f[0, 3], f[0, 4], f[1, 1], f[1, 2], f[1, 3],
f[1, 4], f[2, 1], f[2, 2], f[2, 3], f[2, 4], f[3, 1], f[3, 2],
f[3, 3], f[3, 4], f[4, 1], f[4, 2], f[4, 3], f[4, 4]*
I want to find a way to interject a value m
between each list item, to create
desiredtable=f[0, 1], m, f[0, 2], m, f[0, 3], m, f[0, 4], f[1, 1], m, f[1, 2],
m, f[1, 3], m, f[1, 4], f[2, 1], m, f[2, 2], m, f[2, 3], m,
f[2, 4], f[3, 1], m, f[3, 2], m, f[3, 3], m, f[3, 4], f[4, 1],
m, f[4, 2], m, f[4, 3], m, f[4, 4]
I tried using Riffle
in conjunction with Table
, but it only injects m
in between lines, rather than in between individual entries.
Obviously, with a tiny table like this, it's easy, I can just type in the m
s, or type the Riffle
command once for each line of the output.
But for a very big table, how do I do it?
list-manipulation table
I have table of function f[x,a]
. For the sake of easy reproduction, let's limit it to a few entries - the original is over 1000 x 1000
:
actualtable=Table[f[x, a], x, 0, 4, a, 1, 4]
*f[0, 1], f[0, 2], f[0, 3], f[0, 4], f[1, 1], f[1, 2], f[1, 3],
f[1, 4], f[2, 1], f[2, 2], f[2, 3], f[2, 4], f[3, 1], f[3, 2],
f[3, 3], f[3, 4], f[4, 1], f[4, 2], f[4, 3], f[4, 4]*
I want to find a way to interject a value m
between each list item, to create
desiredtable=f[0, 1], m, f[0, 2], m, f[0, 3], m, f[0, 4], f[1, 1], m, f[1, 2],
m, f[1, 3], m, f[1, 4], f[2, 1], m, f[2, 2], m, f[2, 3], m,
f[2, 4], f[3, 1], m, f[3, 2], m, f[3, 3], m, f[3, 4], f[4, 1],
m, f[4, 2], m, f[4, 3], m, f[4, 4]
I tried using Riffle
in conjunction with Table
, but it only injects m
in between lines, rather than in between individual entries.
Obviously, with a tiny table like this, it's easy, I can just type in the m
s, or type the Riffle
command once for each line of the output.
But for a very big table, how do I do it?
list-manipulation table
list-manipulation table
asked 1 hour ago
Richard Burke-Ward
3237
3237
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Map Riffle to each of the element of actualTable:
desiredtable = Riffle[#, "m"] & /@ actualtable
(* f[0, 1], "m", f[0, 2], "m", f[0, 3], "m", f[0, 4], f[1, 1], "m",
f[1, 2], "m", f[1, 3], "m", f[1, 4], f[2, 1], "m", f[2, 2], "m",
f[2, 3], "m", f[2, 4], f[3, 1], "m", f[3, 2], "m", f[3, 3], "m",
f[3, 4], f[4, 1], "m", f[4, 2], "m", f[4, 3], "m", f[4, 4]*)
Perfect. Thanks.
â Richard Burke-Ward
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Map Riffle to each of the element of actualTable:
desiredtable = Riffle[#, "m"] & /@ actualtable
(* f[0, 1], "m", f[0, 2], "m", f[0, 3], "m", f[0, 4], f[1, 1], "m",
f[1, 2], "m", f[1, 3], "m", f[1, 4], f[2, 1], "m", f[2, 2], "m",
f[2, 3], "m", f[2, 4], f[3, 1], "m", f[3, 2], "m", f[3, 3], "m",
f[3, 4], f[4, 1], "m", f[4, 2], "m", f[4, 3], "m", f[4, 4]*)
Perfect. Thanks.
â Richard Burke-Ward
1 hour ago
add a comment |Â
up vote
2
down vote
accepted
Map Riffle to each of the element of actualTable:
desiredtable = Riffle[#, "m"] & /@ actualtable
(* f[0, 1], "m", f[0, 2], "m", f[0, 3], "m", f[0, 4], f[1, 1], "m",
f[1, 2], "m", f[1, 3], "m", f[1, 4], f[2, 1], "m", f[2, 2], "m",
f[2, 3], "m", f[2, 4], f[3, 1], "m", f[3, 2], "m", f[3, 3], "m",
f[3, 4], f[4, 1], "m", f[4, 2], "m", f[4, 3], "m", f[4, 4]*)
Perfect. Thanks.
â Richard Burke-Ward
1 hour ago
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Map Riffle to each of the element of actualTable:
desiredtable = Riffle[#, "m"] & /@ actualtable
(* f[0, 1], "m", f[0, 2], "m", f[0, 3], "m", f[0, 4], f[1, 1], "m",
f[1, 2], "m", f[1, 3], "m", f[1, 4], f[2, 1], "m", f[2, 2], "m",
f[2, 3], "m", f[2, 4], f[3, 1], "m", f[3, 2], "m", f[3, 3], "m",
f[3, 4], f[4, 1], "m", f[4, 2], "m", f[4, 3], "m", f[4, 4]*)
Map Riffle to each of the element of actualTable:
desiredtable = Riffle[#, "m"] & /@ actualtable
(* f[0, 1], "m", f[0, 2], "m", f[0, 3], "m", f[0, 4], f[1, 1], "m",
f[1, 2], "m", f[1, 3], "m", f[1, 4], f[2, 1], "m", f[2, 2], "m",
f[2, 3], "m", f[2, 4], f[3, 1], "m", f[3, 2], "m", f[3, 3], "m",
f[3, 4], f[4, 1], "m", f[4, 2], "m", f[4, 3], "m", f[4, 4]*)
answered 1 hour ago
FredrikD
5071521
5071521
Perfect. Thanks.
â Richard Burke-Ward
1 hour ago
add a comment |Â
Perfect. Thanks.
â Richard Burke-Ward
1 hour ago
Perfect. Thanks.
â Richard Burke-Ward
1 hour ago
Perfect. Thanks.
â Richard Burke-Ward
1 hour ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181995%2fcombine-table-with-riffle%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password