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













2












$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?










share|improve this question









$endgroup$
















    2












    $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?










    share|improve this question









    $endgroup$














      2












      2








      2


      1



      $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?










      share|improve this question









      $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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 8 hours ago









      Saesun KimSaesun Kim

      7555 silver badges17 bronze badges




      7555 silver badges17 bronze badges




















          5 Answers
          5






          active

          oldest

          votes


















          4












          $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.






          share|improve this answer









          $endgroup$




















            4












            $begingroup$

            Times @@@ # & /@ mylist
            (* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)





            share|improve this answer









            $endgroup$








            • 4




              $begingroup$
              This seems less clear and less general than Apply[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


















            3












            $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







            share|improve this answer











            $endgroup$




















              2












              $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





              share|improve this answer









              $endgroup$




















                1












                $begingroup$

                Map[Times[Sequence @@ #] &] /@ mylist
                (* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)





                share|improve this answer









                $endgroup$















                  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
                  );



                  );













                  draft saved

                  draft discarded


















                  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









                  4












                  $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.






                  share|improve this answer









                  $endgroup$

















                    4












                    $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.






                    share|improve this answer









                    $endgroup$















                      4












                      4








                      4





                      $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.






                      share|improve this answer









                      $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.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered 8 hours ago









                      ShredderroyShredderroy

                      1,79511 silver badges17 bronze badges




                      1,79511 silver badges17 bronze badges





















                          4












                          $begingroup$

                          Times @@@ # & /@ mylist
                          (* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)





                          share|improve this answer









                          $endgroup$








                          • 4




                            $begingroup$
                            This seems less clear and less general than Apply[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












                          $begingroup$

                          Times @@@ # & /@ mylist
                          (* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)





                          share|improve this answer









                          $endgroup$








                          • 4




                            $begingroup$
                            This seems less clear and less general than Apply[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








                          4





                          $begingroup$

                          Times @@@ # & /@ mylist
                          (* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)





                          share|improve this answer









                          $endgroup$



                          Times @@@ # & /@ mylist
                          (* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          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 than Apply[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




                            $begingroup$
                            This seems less clear and less general than Apply[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











                          3












                          $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







                          share|improve this answer











                          $endgroup$

















                            3












                            $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







                            share|improve this answer











                            $endgroup$















                              3












                              3








                              3





                              $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







                              share|improve this answer











                              $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








                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited 3 hours ago

























                              answered 4 hours ago









                              kglrkglr

                              201k10 gold badges230 silver badges459 bronze badges




                              201k10 gold badges230 silver badges459 bronze badges





















                                  2












                                  $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





                                  share|improve this answer









                                  $endgroup$

















                                    2












                                    $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





                                    share|improve this answer









                                    $endgroup$















                                      2












                                      2








                                      2





                                      $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





                                      share|improve this answer









                                      $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






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered 7 hours ago









                                      bill sbill s

                                      55.7k3 gold badges77 silver badges161 bronze badges




                                      55.7k3 gold badges77 silver badges161 bronze badges





















                                          1












                                          $begingroup$

                                          Map[Times[Sequence @@ #] &] /@ mylist
                                          (* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)





                                          share|improve this answer









                                          $endgroup$

















                                            1












                                            $begingroup$

                                            Map[Times[Sequence @@ #] &] /@ mylist
                                            (* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)





                                            share|improve this answer









                                            $endgroup$















                                              1












                                              1








                                              1





                                              $begingroup$

                                              Map[Times[Sequence @@ #] &] /@ mylist
                                              (* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)





                                              share|improve this answer









                                              $endgroup$



                                              Map[Times[Sequence @@ #] &] /@ mylist
                                              (* y1 y2 y3, y3 y4 y5, w1 w2 w3, w4 w5 w6 *)






                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered 7 hours ago









                                              Rohit NamjoshiRohit Namjoshi

                                              1,7151 gold badge3 silver badges15 bronze badges




                                              1,7151 gold badge3 silver badges15 bronze badges



























                                                  draft saved

                                                  draft discarded
















































                                                  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.




                                                  draft saved


                                                  draft discarded














                                                  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





















































                                                  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







                                                  Popular posts from this blog

                                                  Sahara Skak | Bilen | Luke uk diar | NawigatsjuunCommonskategorii: SaharaWikivoyage raisfeerer: Sahara26° N, 13° O

                                                  The fall designs the understood secretary. Looking glass Science Shock Discovery Hot Everybody Loves Raymond Smile 곳 서비스 성실하다 Defas Kaloolon Definition: To combine or impregnate with sulphur or any of its compounds as to sulphurize caoutchouc in vulcanizing Flame colored Reason Useful Thin Help 갖다 유명하다 낙엽 장례식 Country Iron Definition: A fencer a gladiator one who exhibits his skill in the use of the sword Definition: The American black throated bunting Spiza Americana Nostalgic Needy Method to my madness 시키다 평가되다 전부 소설가 우아하다 Argument Tin Feeling Representative Gym Music Gaur Chicken 일쑤 코치 편 학생증 The harbor values the sugar. Vasagle Yammoe Enstatite Definition: Capable of being limited Road Neighborly Five Refer Built Kangaroo 비비다 Degree Release Bargain Horse 하루 형님 유교 석 동부 괴롭히다 경제력

                                                  19. јануар Садржај Догађаји Рођења Смрти Празници и дани сећања Види још Референце Мени за навигацијуу