Simplify the codeMap a function over the columns of an M x N arrayPlaceholders for map inside a mapUsing MapIndexed only at certain elements of a listUsing Map multiple times in one commandHow to subtract the column means from each row of a matrix?Nearest numbers in the listCan I unfold the triangular wave?Selecting Values from a List Above a Certain Numbertwo list manipulation on columnsMultiply two lists
Russian equivalents of 能骗就骗 (if you can cheat, then cheat)
Do electrons really perform instantaneous quantum leaps?
Find the closest three-digit hex colour
Drawing a sigmoid function and its derivative in tikz
Does "boire un jus" tend to mean "coffee" or "juice of fruit"?
Tikz radius of the bullets with node
Any Tips On Writing Extended Recollection In A Novel
How many transistors are there in a logic gate?
Apollo Mission Operations Control Room 2 display, what do these numbers indicate?
Have any large aeroplanes been landed — safely and without damage — in locations that they could not be flown away from?
What was the point of separating stdout and stderr?
How do I present a future free of gender stereotypes without being jarring or overpowering the narrative?
What's the lunar calendar of two moons
Does a lens with a bigger max. aperture focus faster than a lens with a smaller max. aperture?
Why will we fail creating a self sustaining off world colony?
How does mmorpg store data?
How to track mail undetectably?
Active wildlife outside the window- Good or Bad for Cat psychology?
iMac 2019: Can I mix the old modules with the new ones when upgrading RAM?
Is it OK to throw pebbles and stones in streams, waterfalls, ponds, etc.?
Installed software from source, how to say yum not to install it from package?
How to stop QGIS from looking for the wrong PostgreSQL host address in an existing workproject?
Is it advisable to inform the CEO about his brother accessing his office?
Why was Pan Am Flight 103 flying over Lockerbie?
Simplify the code
Map a function over the columns of an M x N arrayPlaceholders for map inside a mapUsing MapIndexed only at certain elements of a listUsing Map multiple times in one commandHow to subtract the column means from each row of a matrix?Nearest numbers in the listCan I unfold the triangular wave?Selecting Values from a List Above a Certain Numbertwo list manipulation on columnsMultiply two lists
$begingroup$
I have a function that grabs the second part of the list and change it to times,
mylist = y1, y2, y3, y3, y4, y5, w1, w2, w3, w4, w5, w6;
g[x_] := x /. List -> Times
Map[g, mylist, 2]
I wrote it above, but I think I should be able to make it much simpler code using @ # and &. Any suggestion?
list-manipulation map
$endgroup$
add a comment |
$begingroup$
I have a function that grabs the second part of the list and change it to times,
mylist = y1, y2, y3, y3, y4, y5, w1, w2, w3, w4, w5, w6;
g[x_] := x /. List -> Times
Map[g, mylist, 2]
I wrote it above, but I think I should be able to make it much simpler code using @ # and &. Any suggestion?
list-manipulation map
$endgroup$
add a comment |
$begingroup$
I have a function that grabs the second part of the list and change it to times,
mylist = y1, y2, y3, y3, y4, y5, w1, w2, w3, w4, w5, w6;
g[x_] := x /. List -> Times
Map[g, mylist, 2]
I wrote it above, but I think I should be able to make it much simpler code using @ # and &. Any suggestion?
list-manipulation map
$endgroup$
I have a function that grabs the second part of the list and change it to times,
mylist = y1, y2, y3, y3, y4, y5, w1, w2, w3, w4, w5, w6;
g[x_] := x /. List -> Times
Map[g, mylist, 2]
I wrote it above, but I think I should be able to make it much simpler code using @ # and &. Any suggestion?
list-manipulation map
list-manipulation map
asked 8 hours ago
Saesun KimSaesun Kim
7555 silver badges17 bronze badges
7555 silver badges17 bronze badges
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
$begingroup$
Since you appear to want to multiply the list only when all of its elements are atomic, how about just
mylist /. s__?AtomQ :> Times[s]
It appears to be the most direct translation of your thought.
$endgroup$
add a comment |
$begingroup$
Times @@@ # & /@ mylist
(* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)
$endgroup$
4
$begingroup$
This seems less clear and less general thanApply[Times, mylist, 2]or ...-2.
$endgroup$
– lirtosiast
7 hours ago
3
$begingroup$
@lirtosiast oh yes for sure, but the OP was specifically asking for @ # & gobbledygook :-) Ideally there would be a@@@@operator for this purpose.
$endgroup$
– Roman
7 hours ago
$begingroup$
Thank you so much for the clear and nice answer!
$endgroup$
– Saesun Kim
7 hours ago
add a comment |
$begingroup$
☺lookMaNoLetters☺ = 1 ## & @@@ # & /@ # &;
☺lookMaNoLetters☺ @ mylist
y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6
You can use as many @s as you like:
☺♬♪♫♪☺ = ## & @@@ (## & @@@ ## & @@@ 1 ## & @@@ ## & @@@ ## & /@ #) &;
☺♬♪♫♪☺ @ mylist
y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6
$endgroup$
add a comment |
$begingroup$
Another way to view your function is as a generalized inner product:
Inner[Times, mylist, 1, 1, 1, Times]
y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6
$endgroup$
add a comment |
$begingroup$
Map[Times[Sequence @@ #] &] /@ mylist
(* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201231%2fsimplify-the-code%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Since you appear to want to multiply the list only when all of its elements are atomic, how about just
mylist /. s__?AtomQ :> Times[s]
It appears to be the most direct translation of your thought.
$endgroup$
add a comment |
$begingroup$
Since you appear to want to multiply the list only when all of its elements are atomic, how about just
mylist /. s__?AtomQ :> Times[s]
It appears to be the most direct translation of your thought.
$endgroup$
add a comment |
$begingroup$
Since you appear to want to multiply the list only when all of its elements are atomic, how about just
mylist /. s__?AtomQ :> Times[s]
It appears to be the most direct translation of your thought.
$endgroup$
Since you appear to want to multiply the list only when all of its elements are atomic, how about just
mylist /. s__?AtomQ :> Times[s]
It appears to be the most direct translation of your thought.
answered 8 hours ago
ShredderroyShredderroy
1,79511 silver badges17 bronze badges
1,79511 silver badges17 bronze badges
add a comment |
add a comment |
$begingroup$
Times @@@ # & /@ mylist
(* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)
$endgroup$
4
$begingroup$
This seems less clear and less general thanApply[Times, mylist, 2]or ...-2.
$endgroup$
– lirtosiast
7 hours ago
3
$begingroup$
@lirtosiast oh yes for sure, but the OP was specifically asking for @ # & gobbledygook :-) Ideally there would be a@@@@operator for this purpose.
$endgroup$
– Roman
7 hours ago
$begingroup$
Thank you so much for the clear and nice answer!
$endgroup$
– Saesun Kim
7 hours ago
add a comment |
$begingroup$
Times @@@ # & /@ mylist
(* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)
$endgroup$
4
$begingroup$
This seems less clear and less general thanApply[Times, mylist, 2]or ...-2.
$endgroup$
– lirtosiast
7 hours ago
3
$begingroup$
@lirtosiast oh yes for sure, but the OP was specifically asking for @ # & gobbledygook :-) Ideally there would be a@@@@operator for this purpose.
$endgroup$
– Roman
7 hours ago
$begingroup$
Thank you so much for the clear and nice answer!
$endgroup$
– Saesun Kim
7 hours ago
add a comment |
$begingroup$
Times @@@ # & /@ mylist
(* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)
$endgroup$
Times @@@ # & /@ mylist
(* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)
answered 8 hours ago
RomanRoman
12.3k1 gold badge19 silver badges50 bronze badges
12.3k1 gold badge19 silver badges50 bronze badges
4
$begingroup$
This seems less clear and less general thanApply[Times, mylist, 2]or ...-2.
$endgroup$
– lirtosiast
7 hours ago
3
$begingroup$
@lirtosiast oh yes for sure, but the OP was specifically asking for @ # & gobbledygook :-) Ideally there would be a@@@@operator for this purpose.
$endgroup$
– Roman
7 hours ago
$begingroup$
Thank you so much for the clear and nice answer!
$endgroup$
– Saesun Kim
7 hours ago
add a comment |
4
$begingroup$
This seems less clear and less general thanApply[Times, mylist, 2]or ...-2.
$endgroup$
– lirtosiast
7 hours ago
3
$begingroup$
@lirtosiast oh yes for sure, but the OP was specifically asking for @ # & gobbledygook :-) Ideally there would be a@@@@operator for this purpose.
$endgroup$
– Roman
7 hours ago
$begingroup$
Thank you so much for the clear and nice answer!
$endgroup$
– Saesun Kim
7 hours ago
4
4
$begingroup$
This seems less clear and less general than
Apply[Times, mylist, 2] or ...-2.$endgroup$
– lirtosiast
7 hours ago
$begingroup$
This seems less clear and less general than
Apply[Times, mylist, 2] or ...-2.$endgroup$
– lirtosiast
7 hours ago
3
3
$begingroup$
@lirtosiast oh yes for sure, but the OP was specifically asking for @ # & gobbledygook :-) Ideally there would be a
@@@@ operator for this purpose.$endgroup$
– Roman
7 hours ago
$begingroup$
@lirtosiast oh yes for sure, but the OP was specifically asking for @ # & gobbledygook :-) Ideally there would be a
@@@@ operator for this purpose.$endgroup$
– Roman
7 hours ago
$begingroup$
Thank you so much for the clear and nice answer!
$endgroup$
– Saesun Kim
7 hours ago
$begingroup$
Thank you so much for the clear and nice answer!
$endgroup$
– Saesun Kim
7 hours ago
add a comment |
$begingroup$
☺lookMaNoLetters☺ = 1 ## & @@@ # & /@ # &;
☺lookMaNoLetters☺ @ mylist
y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6
You can use as many @s as you like:
☺♬♪♫♪☺ = ## & @@@ (## & @@@ ## & @@@ 1 ## & @@@ ## & @@@ ## & /@ #) &;
☺♬♪♫♪☺ @ mylist
y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6
$endgroup$
add a comment |
$begingroup$
☺lookMaNoLetters☺ = 1 ## & @@@ # & /@ # &;
☺lookMaNoLetters☺ @ mylist
y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6
You can use as many @s as you like:
☺♬♪♫♪☺ = ## & @@@ (## & @@@ ## & @@@ 1 ## & @@@ ## & @@@ ## & /@ #) &;
☺♬♪♫♪☺ @ mylist
y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6
$endgroup$
add a comment |
$begingroup$
☺lookMaNoLetters☺ = 1 ## & @@@ # & /@ # &;
☺lookMaNoLetters☺ @ mylist
y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6
You can use as many @s as you like:
☺♬♪♫♪☺ = ## & @@@ (## & @@@ ## & @@@ 1 ## & @@@ ## & @@@ ## & /@ #) &;
☺♬♪♫♪☺ @ mylist
y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6
$endgroup$
☺lookMaNoLetters☺ = 1 ## & @@@ # & /@ # &;
☺lookMaNoLetters☺ @ mylist
y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6
You can use as many @s as you like:
☺♬♪♫♪☺ = ## & @@@ (## & @@@ ## & @@@ 1 ## & @@@ ## & @@@ ## & /@ #) &;
☺♬♪♫♪☺ @ mylist
y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6
edited 3 hours ago
answered 4 hours ago
kglrkglr
201k10 gold badges230 silver badges459 bronze badges
201k10 gold badges230 silver badges459 bronze badges
add a comment |
add a comment |
$begingroup$
Another way to view your function is as a generalized inner product:
Inner[Times, mylist, 1, 1, 1, Times]
y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6
$endgroup$
add a comment |
$begingroup$
Another way to view your function is as a generalized inner product:
Inner[Times, mylist, 1, 1, 1, Times]
y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6
$endgroup$
add a comment |
$begingroup$
Another way to view your function is as a generalized inner product:
Inner[Times, mylist, 1, 1, 1, Times]
y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6
$endgroup$
Another way to view your function is as a generalized inner product:
Inner[Times, mylist, 1, 1, 1, Times]
y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6
answered 7 hours ago
bill sbill s
55.7k3 gold badges77 silver badges161 bronze badges
55.7k3 gold badges77 silver badges161 bronze badges
add a comment |
add a comment |
$begingroup$
Map[Times[Sequence @@ #] &] /@ mylist
(* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)
$endgroup$
add a comment |
$begingroup$
Map[Times[Sequence @@ #] &] /@ mylist
(* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)
$endgroup$
add a comment |
$begingroup$
Map[Times[Sequence @@ #] &] /@ mylist
(* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)
$endgroup$
Map[Times[Sequence @@ #] &] /@ mylist
(* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)
answered 7 hours ago
Rohit NamjoshiRohit Namjoshi
1,7151 gold badge3 silver badges15 bronze badges
1,7151 gold badge3 silver badges15 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201231%2fsimplify-the-code%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown