Positioning in a list









up vote
5
down vote

favorite












I have the following list:



l=2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x


I want to pick those elements that have coefficients bigger than 1, i.e. 2 x, 4 x, 2 x, 4 x, 2 x
I tried



Select[CoefficientList[2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x, 
x][[All, 2]], # > 1 &]*x


which return what I need but I believe there must be a much shorter and faster way? Also I would like to find the position of 2 x, 4 x, 2 x, 4 x, 2 x in my original list so I did:



Position[2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x, 2 x, 4 x, 2 x, 
4 x, 2 x]


which does not work so I must be wrong










share|improve this question

























    up vote
    5
    down vote

    favorite












    I have the following list:



    l=2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x


    I want to pick those elements that have coefficients bigger than 1, i.e. 2 x, 4 x, 2 x, 4 x, 2 x
    I tried



    Select[CoefficientList[2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x, 
    x][[All, 2]], # > 1 &]*x


    which return what I need but I believe there must be a much shorter and faster way? Also I would like to find the position of 2 x, 4 x, 2 x, 4 x, 2 x in my original list so I did:



    Position[2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x, 2 x, 4 x, 2 x, 
    4 x, 2 x]


    which does not work so I must be wrong










    share|improve this question























      up vote
      5
      down vote

      favorite









      up vote
      5
      down vote

      favorite











      I have the following list:



      l=2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x


      I want to pick those elements that have coefficients bigger than 1, i.e. 2 x, 4 x, 2 x, 4 x, 2 x
      I tried



      Select[CoefficientList[2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x, 
      x][[All, 2]], # > 1 &]*x


      which return what I need but I believe there must be a much shorter and faster way? Also I would like to find the position of 2 x, 4 x, 2 x, 4 x, 2 x in my original list so I did:



      Position[2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x, 2 x, 4 x, 2 x, 
      4 x, 2 x]


      which does not work so I must be wrong










      share|improve this question













      I have the following list:



      l=2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x


      I want to pick those elements that have coefficients bigger than 1, i.e. 2 x, 4 x, 2 x, 4 x, 2 x
      I tried



      Select[CoefficientList[2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x, 
      x][[All, 2]], # > 1 &]*x


      which return what I need but I believe there must be a much shorter and faster way? Also I would like to find the position of 2 x, 4 x, 2 x, 4 x, 2 x in my original list so I did:



      Position[2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x, 2 x, 4 x, 2 x, 
      4 x, 2 x]


      which does not work so I must be wrong







      list-manipulation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      William

      55628




      55628




















          5 Answers
          5






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          l = 2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x;

          s = Select[CoefficientList[l, x][[All, 2]], # > 1 &]*x

          p = Position[l, Alternatives @@ Union[s]]



          1, 3, 6, 7, 10




          Extract[l, p]





          share|improve this answer





























            up vote
            4
            down vote













            You might do like this:



            l /. x -> 1 /. x_ /; x == 1 -> Nothing /. a_ -> a*x
            (* 2 x, 4 x, 2 x, 4 x, 2 x *)


            Have fun!






            share|improve this answer



























              up vote
              4
              down vote













              You can try



              Pick[l,Exponent[x,l],0] 



              2 x, 4 x, 2 x, 4 x, 2 x




              or



              Flatten[Take[l,#]&/@Position[Exponent[x,l],0]] 


              Also if you want the positions try



              Position[Exponent[x, l], 0] 



              1, 3, 6, 7, 10







              share|improve this answer





























                up vote
                3
                down vote













                l = 2 x, x, 4 x, -x, x, 2 x, 4 x, x, x, 2 x;
                test = Clip[Coefficient[l, x], 1, 1, 1, 0]; (* 1 means coeffient <= 1, else 0 *)
                l2 = Pick[l, test, 0]
                pos = Ordering[test, Length[l2]]



                2 x, 4 x, 2 x, 4 x, 2 x

                1, 3, 6, 7, 10







                share|improve this answer





























                  up vote
                  2
                  down vote













                  l=2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x;
                  Pick[l, Unitize[D[l, x] - 1], 1]



                  2 x, 4 x, 2 x, 4 x, 2 x




                   Flatten@Position[Unitize[D[l, x] - 1], 1]



                  1, 3, 6, 7, 10







                  share|improve this answer




















                    Your Answer





                    StackExchange.ifUsing("editor", function ()
                    return StackExchange.using("mathjaxEditing", function ()
                    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
                    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
                    );
                    );
                    , "mathjax-editing");

                    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',
                    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%2f185678%2fpositioning-in-a-list%23new-answer', 'question_page');

                    );

                    Post as a guest






























                    5 Answers
                    5






                    active

                    oldest

                    votes








                    5 Answers
                    5






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes








                    up vote
                    4
                    down vote



                    accepted










                    l = 2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x;

                    s = Select[CoefficientList[l, x][[All, 2]], # > 1 &]*x

                    p = Position[l, Alternatives @@ Union[s]]



                    1, 3, 6, 7, 10




                    Extract[l, p]





                    share|improve this answer


























                      up vote
                      4
                      down vote



                      accepted










                      l = 2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x;

                      s = Select[CoefficientList[l, x][[All, 2]], # > 1 &]*x

                      p = Position[l, Alternatives @@ Union[s]]



                      1, 3, 6, 7, 10




                      Extract[l, p]





                      share|improve this answer
























                        up vote
                        4
                        down vote



                        accepted







                        up vote
                        4
                        down vote



                        accepted






                        l = 2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x;

                        s = Select[CoefficientList[l, x][[All, 2]], # > 1 &]*x

                        p = Position[l, Alternatives @@ Union[s]]



                        1, 3, 6, 7, 10




                        Extract[l, p]





                        share|improve this answer














                        l = 2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x;

                        s = Select[CoefficientList[l, x][[All, 2]], # > 1 &]*x

                        p = Position[l, Alternatives @@ Union[s]]



                        1, 3, 6, 7, 10




                        Extract[l, p]






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited yesterday

























                        answered yesterday









                        Chris Degnen

                        21.6k23482




                        21.6k23482




















                            up vote
                            4
                            down vote













                            You might do like this:



                            l /. x -> 1 /. x_ /; x == 1 -> Nothing /. a_ -> a*x
                            (* 2 x, 4 x, 2 x, 4 x, 2 x *)


                            Have fun!






                            share|improve this answer
























                              up vote
                              4
                              down vote













                              You might do like this:



                              l /. x -> 1 /. x_ /; x == 1 -> Nothing /. a_ -> a*x
                              (* 2 x, 4 x, 2 x, 4 x, 2 x *)


                              Have fun!






                              share|improve this answer






















                                up vote
                                4
                                down vote










                                up vote
                                4
                                down vote









                                You might do like this:



                                l /. x -> 1 /. x_ /; x == 1 -> Nothing /. a_ -> a*x
                                (* 2 x, 4 x, 2 x, 4 x, 2 x *)


                                Have fun!






                                share|improve this answer












                                You might do like this:



                                l /. x -> 1 /. x_ /; x == 1 -> Nothing /. a_ -> a*x
                                (* 2 x, 4 x, 2 x, 4 x, 2 x *)


                                Have fun!







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered yesterday









                                Alexei Boulbitch

                                20.9k2369




                                20.9k2369




















                                    up vote
                                    4
                                    down vote













                                    You can try



                                    Pick[l,Exponent[x,l],0] 



                                    2 x, 4 x, 2 x, 4 x, 2 x




                                    or



                                    Flatten[Take[l,#]&/@Position[Exponent[x,l],0]] 


                                    Also if you want the positions try



                                    Position[Exponent[x, l], 0] 



                                    1, 3, 6, 7, 10







                                    share|improve this answer


























                                      up vote
                                      4
                                      down vote













                                      You can try



                                      Pick[l,Exponent[x,l],0] 



                                      2 x, 4 x, 2 x, 4 x, 2 x




                                      or



                                      Flatten[Take[l,#]&/@Position[Exponent[x,l],0]] 


                                      Also if you want the positions try



                                      Position[Exponent[x, l], 0] 



                                      1, 3, 6, 7, 10







                                      share|improve this answer
























                                        up vote
                                        4
                                        down vote










                                        up vote
                                        4
                                        down vote









                                        You can try



                                        Pick[l,Exponent[x,l],0] 



                                        2 x, 4 x, 2 x, 4 x, 2 x




                                        or



                                        Flatten[Take[l,#]&/@Position[Exponent[x,l],0]] 


                                        Also if you want the positions try



                                        Position[Exponent[x, l], 0] 



                                        1, 3, 6, 7, 10







                                        share|improve this answer














                                        You can try



                                        Pick[l,Exponent[x,l],0] 



                                        2 x, 4 x, 2 x, 4 x, 2 x




                                        or



                                        Flatten[Take[l,#]&/@Position[Exponent[x,l],0]] 


                                        Also if you want the positions try



                                        Position[Exponent[x, l], 0] 



                                        1, 3, 6, 7, 10








                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited yesterday

























                                        answered yesterday









                                        J42161217

                                        2,763218




                                        2,763218




















                                            up vote
                                            3
                                            down vote













                                            l = 2 x, x, 4 x, -x, x, 2 x, 4 x, x, x, 2 x;
                                            test = Clip[Coefficient[l, x], 1, 1, 1, 0]; (* 1 means coeffient <= 1, else 0 *)
                                            l2 = Pick[l, test, 0]
                                            pos = Ordering[test, Length[l2]]



                                            2 x, 4 x, 2 x, 4 x, 2 x

                                            1, 3, 6, 7, 10







                                            share|improve this answer


























                                              up vote
                                              3
                                              down vote













                                              l = 2 x, x, 4 x, -x, x, 2 x, 4 x, x, x, 2 x;
                                              test = Clip[Coefficient[l, x], 1, 1, 1, 0]; (* 1 means coeffient <= 1, else 0 *)
                                              l2 = Pick[l, test, 0]
                                              pos = Ordering[test, Length[l2]]



                                              2 x, 4 x, 2 x, 4 x, 2 x

                                              1, 3, 6, 7, 10







                                              share|improve this answer
























                                                up vote
                                                3
                                                down vote










                                                up vote
                                                3
                                                down vote









                                                l = 2 x, x, 4 x, -x, x, 2 x, 4 x, x, x, 2 x;
                                                test = Clip[Coefficient[l, x], 1, 1, 1, 0]; (* 1 means coeffient <= 1, else 0 *)
                                                l2 = Pick[l, test, 0]
                                                pos = Ordering[test, Length[l2]]



                                                2 x, 4 x, 2 x, 4 x, 2 x

                                                1, 3, 6, 7, 10







                                                share|improve this answer














                                                l = 2 x, x, 4 x, -x, x, 2 x, 4 x, x, x, 2 x;
                                                test = Clip[Coefficient[l, x], 1, 1, 1, 0]; (* 1 means coeffient <= 1, else 0 *)
                                                l2 = Pick[l, test, 0]
                                                pos = Ordering[test, Length[l2]]



                                                2 x, 4 x, 2 x, 4 x, 2 x

                                                1, 3, 6, 7, 10








                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited yesterday

























                                                answered yesterday









                                                Coolwater

                                                13.9k32351




                                                13.9k32351




















                                                    up vote
                                                    2
                                                    down vote













                                                    l=2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x;
                                                    Pick[l, Unitize[D[l, x] - 1], 1]



                                                    2 x, 4 x, 2 x, 4 x, 2 x




                                                     Flatten@Position[Unitize[D[l, x] - 1], 1]



                                                    1, 3, 6, 7, 10







                                                    share|improve this answer
























                                                      up vote
                                                      2
                                                      down vote













                                                      l=2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x;
                                                      Pick[l, Unitize[D[l, x] - 1], 1]



                                                      2 x, 4 x, 2 x, 4 x, 2 x




                                                       Flatten@Position[Unitize[D[l, x] - 1], 1]



                                                      1, 3, 6, 7, 10







                                                      share|improve this answer






















                                                        up vote
                                                        2
                                                        down vote










                                                        up vote
                                                        2
                                                        down vote









                                                        l=2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x;
                                                        Pick[l, Unitize[D[l, x] - 1], 1]



                                                        2 x, 4 x, 2 x, 4 x, 2 x




                                                         Flatten@Position[Unitize[D[l, x] - 1], 1]



                                                        1, 3, 6, 7, 10







                                                        share|improve this answer












                                                        l=2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x;
                                                        Pick[l, Unitize[D[l, x] - 1], 1]



                                                        2 x, 4 x, 2 x, 4 x, 2 x




                                                         Flatten@Position[Unitize[D[l, x] - 1], 1]



                                                        1, 3, 6, 7, 10








                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered yesterday









                                                        Okkes Dulgerci

                                                        3,4611716




                                                        3,4611716



























                                                             

                                                            draft saved


                                                            draft discarded















































                                                             


                                                            draft saved


                                                            draft discarded














                                                            StackExchange.ready(
                                                            function ()
                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f185678%2fpositioning-in-a-list%23new-answer', 'question_page');

                                                            );

                                                            Post as a guest














































































                                                            這個網誌中的熱門文章

                                                            How to read a connectionString WITH PROVIDER in .NET Core?

                                                            Node.js Script on GitHub Pages or Amazon S3

                                                            Museum of Modern and Contemporary Art of Trento and Rovereto