Applying a lower bound threshold on a list

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












Consider the following list



list=0,0,0,10^-18,10^-15,10^-12,10^-10,1,1


How can I apply a threshold on the list that will give a lower bound for the values. For example



ApplyThreshold[list,10^-12];


will yield an outcome of



 10^-12,10^-12,10^-12,10^-12,10^-12,10^-12,10^-10,1,1


and



ApplyThreshold[list,10^-9];


will yield an outcome of



 10^-9,10^-9,10^-9,10^-9,10^-9,10^-9,10^-9,1,1






share|improve this question
























    up vote
    3
    down vote

    favorite












    Consider the following list



    list=0,0,0,10^-18,10^-15,10^-12,10^-10,1,1


    How can I apply a threshold on the list that will give a lower bound for the values. For example



    ApplyThreshold[list,10^-12];


    will yield an outcome of



     10^-12,10^-12,10^-12,10^-12,10^-12,10^-12,10^-10,1,1


    and



    ApplyThreshold[list,10^-9];


    will yield an outcome of



     10^-9,10^-9,10^-9,10^-9,10^-9,10^-9,10^-9,1,1






    share|improve this question






















      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      Consider the following list



      list=0,0,0,10^-18,10^-15,10^-12,10^-10,1,1


      How can I apply a threshold on the list that will give a lower bound for the values. For example



      ApplyThreshold[list,10^-12];


      will yield an outcome of



       10^-12,10^-12,10^-12,10^-12,10^-12,10^-12,10^-10,1,1


      and



      ApplyThreshold[list,10^-9];


      will yield an outcome of



       10^-9,10^-9,10^-9,10^-9,10^-9,10^-9,10^-9,1,1






      share|improve this question












      Consider the following list



      list=0,0,0,10^-18,10^-15,10^-12,10^-10,1,1


      How can I apply a threshold on the list that will give a lower bound for the values. For example



      ApplyThreshold[list,10^-12];


      will yield an outcome of



       10^-12,10^-12,10^-12,10^-12,10^-12,10^-12,10^-10,1,1


      and



      ApplyThreshold[list,10^-9];


      will yield an outcome of



       10^-9,10^-9,10^-9,10^-9,10^-9,10^-9,10^-9,1,1








      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 26 at 9:20









      jarhead

      689412




      689412




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          7
          down vote



          accepted










          You can use Clip, Ramp or Max:



          Clip[list, 10^-9, ∞]



          1/1000000000, 1/1000000000, 1/1000000000, 1/1000000000,
          1/1000000000, 1/1000000000, 1/1000000000, 1, 1




          Ramp[list - 10^-9] + 10^-9 === Max[#, 10^-9] & /@ list === %



          True




          Timings:



          SeedRandom[1]
          lst = RandomReal[1, 100000];

          (r1 = Ramp[lst - 10^-9] + 10^-9 ;) // RepeatedTiming // First



          0.00017




          (r2 = Clip[lst , 10^-9, Infinity];) // RepeatedTiming // First 



          0.000221




          (r3 = Max[#, 10^-9] & /@ lst ;) // RepeatedTiming // First 



          0.129




          (r4 = Map[crit[#, 1*10^-12] &, lst ];) // RepeatedTiming // First (* from Alexei's answer*)



          0.185




          r1 == r2 == r3 == r4



          True







          share|improve this answer





























            up vote
            2
            down vote













            Try the following. This si your list:



            lst = 0, 0, 0, 10^-18, 10^-15, 10^-12, 10^-10, 1, 1


            This function transforms any number to what you want:



            crit[x_, y_] := If[x >= y, x, y];


            This applies it to the list:



            Map[crit[#, 1*10^-12] &, lst]

            (* 1/1000000000000, 1/1000000000000, 1/1000000000000, 1/1000000000000,
            1/1000000000000, 1/1000000000000, 1/10000000000, 1, 1 *)


            Here is another example of yours:



            Map[crit[#, 1*10^-9] &, lst]

            (* 1/1000000000, 1/1000000000, 1/1000000000, 1/1000000000,
            1/1000000000, 1/1000000000, 1/1000000000, 1, 1 *)


            Have fun!






            share|improve this answer



























              up vote
              1
              down vote













              You can do this succinctly with the ReplaceAll (/.) and Condition (/;) operators:



              list /. x_ /; x < 10^-12 -> 10^-12





              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: false,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                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%2f180674%2fapplying-a-lower-bound-threshold-on-a-list%23new-answer', 'question_page');

                );

                Post as a guest






























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                7
                down vote



                accepted










                You can use Clip, Ramp or Max:



                Clip[list, 10^-9, ∞]



                1/1000000000, 1/1000000000, 1/1000000000, 1/1000000000,
                1/1000000000, 1/1000000000, 1/1000000000, 1, 1




                Ramp[list - 10^-9] + 10^-9 === Max[#, 10^-9] & /@ list === %



                True




                Timings:



                SeedRandom[1]
                lst = RandomReal[1, 100000];

                (r1 = Ramp[lst - 10^-9] + 10^-9 ;) // RepeatedTiming // First



                0.00017




                (r2 = Clip[lst , 10^-9, Infinity];) // RepeatedTiming // First 



                0.000221




                (r3 = Max[#, 10^-9] & /@ lst ;) // RepeatedTiming // First 



                0.129




                (r4 = Map[crit[#, 1*10^-12] &, lst ];) // RepeatedTiming // First (* from Alexei's answer*)



                0.185




                r1 == r2 == r3 == r4



                True







                share|improve this answer


























                  up vote
                  7
                  down vote



                  accepted










                  You can use Clip, Ramp or Max:



                  Clip[list, 10^-9, ∞]



                  1/1000000000, 1/1000000000, 1/1000000000, 1/1000000000,
                  1/1000000000, 1/1000000000, 1/1000000000, 1, 1




                  Ramp[list - 10^-9] + 10^-9 === Max[#, 10^-9] & /@ list === %



                  True




                  Timings:



                  SeedRandom[1]
                  lst = RandomReal[1, 100000];

                  (r1 = Ramp[lst - 10^-9] + 10^-9 ;) // RepeatedTiming // First



                  0.00017




                  (r2 = Clip[lst , 10^-9, Infinity];) // RepeatedTiming // First 



                  0.000221




                  (r3 = Max[#, 10^-9] & /@ lst ;) // RepeatedTiming // First 



                  0.129




                  (r4 = Map[crit[#, 1*10^-12] &, lst ];) // RepeatedTiming // First (* from Alexei's answer*)



                  0.185




                  r1 == r2 == r3 == r4



                  True







                  share|improve this answer
























                    up vote
                    7
                    down vote



                    accepted







                    up vote
                    7
                    down vote



                    accepted






                    You can use Clip, Ramp or Max:



                    Clip[list, 10^-9, ∞]



                    1/1000000000, 1/1000000000, 1/1000000000, 1/1000000000,
                    1/1000000000, 1/1000000000, 1/1000000000, 1, 1




                    Ramp[list - 10^-9] + 10^-9 === Max[#, 10^-9] & /@ list === %



                    True




                    Timings:



                    SeedRandom[1]
                    lst = RandomReal[1, 100000];

                    (r1 = Ramp[lst - 10^-9] + 10^-9 ;) // RepeatedTiming // First



                    0.00017




                    (r2 = Clip[lst , 10^-9, Infinity];) // RepeatedTiming // First 



                    0.000221




                    (r3 = Max[#, 10^-9] & /@ lst ;) // RepeatedTiming // First 



                    0.129




                    (r4 = Map[crit[#, 1*10^-12] &, lst ];) // RepeatedTiming // First (* from Alexei's answer*)



                    0.185




                    r1 == r2 == r3 == r4



                    True







                    share|improve this answer














                    You can use Clip, Ramp or Max:



                    Clip[list, 10^-9, ∞]



                    1/1000000000, 1/1000000000, 1/1000000000, 1/1000000000,
                    1/1000000000, 1/1000000000, 1/1000000000, 1, 1




                    Ramp[list - 10^-9] + 10^-9 === Max[#, 10^-9] & /@ list === %



                    True




                    Timings:



                    SeedRandom[1]
                    lst = RandomReal[1, 100000];

                    (r1 = Ramp[lst - 10^-9] + 10^-9 ;) // RepeatedTiming // First



                    0.00017




                    (r2 = Clip[lst , 10^-9, Infinity];) // RepeatedTiming // First 



                    0.000221




                    (r3 = Max[#, 10^-9] & /@ lst ;) // RepeatedTiming // First 



                    0.129




                    (r4 = Map[crit[#, 1*10^-12] &, lst ];) // RepeatedTiming // First (* from Alexei's answer*)



                    0.185




                    r1 == r2 == r3 == r4



                    True








                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Aug 26 at 10:43

























                    answered Aug 26 at 9:32









                    kglr

                    158k8183382




                    158k8183382




















                        up vote
                        2
                        down vote













                        Try the following. This si your list:



                        lst = 0, 0, 0, 10^-18, 10^-15, 10^-12, 10^-10, 1, 1


                        This function transforms any number to what you want:



                        crit[x_, y_] := If[x >= y, x, y];


                        This applies it to the list:



                        Map[crit[#, 1*10^-12] &, lst]

                        (* 1/1000000000000, 1/1000000000000, 1/1000000000000, 1/1000000000000,
                        1/1000000000000, 1/1000000000000, 1/10000000000, 1, 1 *)


                        Here is another example of yours:



                        Map[crit[#, 1*10^-9] &, lst]

                        (* 1/1000000000, 1/1000000000, 1/1000000000, 1/1000000000,
                        1/1000000000, 1/1000000000, 1/1000000000, 1, 1 *)


                        Have fun!






                        share|improve this answer
























                          up vote
                          2
                          down vote













                          Try the following. This si your list:



                          lst = 0, 0, 0, 10^-18, 10^-15, 10^-12, 10^-10, 1, 1


                          This function transforms any number to what you want:



                          crit[x_, y_] := If[x >= y, x, y];


                          This applies it to the list:



                          Map[crit[#, 1*10^-12] &, lst]

                          (* 1/1000000000000, 1/1000000000000, 1/1000000000000, 1/1000000000000,
                          1/1000000000000, 1/1000000000000, 1/10000000000, 1, 1 *)


                          Here is another example of yours:



                          Map[crit[#, 1*10^-9] &, lst]

                          (* 1/1000000000, 1/1000000000, 1/1000000000, 1/1000000000,
                          1/1000000000, 1/1000000000, 1/1000000000, 1, 1 *)


                          Have fun!






                          share|improve this answer






















                            up vote
                            2
                            down vote










                            up vote
                            2
                            down vote









                            Try the following. This si your list:



                            lst = 0, 0, 0, 10^-18, 10^-15, 10^-12, 10^-10, 1, 1


                            This function transforms any number to what you want:



                            crit[x_, y_] := If[x >= y, x, y];


                            This applies it to the list:



                            Map[crit[#, 1*10^-12] &, lst]

                            (* 1/1000000000000, 1/1000000000000, 1/1000000000000, 1/1000000000000,
                            1/1000000000000, 1/1000000000000, 1/10000000000, 1, 1 *)


                            Here is another example of yours:



                            Map[crit[#, 1*10^-9] &, lst]

                            (* 1/1000000000, 1/1000000000, 1/1000000000, 1/1000000000,
                            1/1000000000, 1/1000000000, 1/1000000000, 1, 1 *)


                            Have fun!






                            share|improve this answer












                            Try the following. This si your list:



                            lst = 0, 0, 0, 10^-18, 10^-15, 10^-12, 10^-10, 1, 1


                            This function transforms any number to what you want:



                            crit[x_, y_] := If[x >= y, x, y];


                            This applies it to the list:



                            Map[crit[#, 1*10^-12] &, lst]

                            (* 1/1000000000000, 1/1000000000000, 1/1000000000000, 1/1000000000000,
                            1/1000000000000, 1/1000000000000, 1/10000000000, 1, 1 *)


                            Here is another example of yours:



                            Map[crit[#, 1*10^-9] &, lst]

                            (* 1/1000000000, 1/1000000000, 1/1000000000, 1/1000000000,
                            1/1000000000, 1/1000000000, 1/1000000000, 1, 1 *)


                            Have fun!







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Aug 26 at 9:37









                            Alexei Boulbitch

                            20.3k2368




                            20.3k2368




















                                up vote
                                1
                                down vote













                                You can do this succinctly with the ReplaceAll (/.) and Condition (/;) operators:



                                list /. x_ /; x < 10^-12 -> 10^-12





                                share|improve this answer
























                                  up vote
                                  1
                                  down vote













                                  You can do this succinctly with the ReplaceAll (/.) and Condition (/;) operators:



                                  list /. x_ /; x < 10^-12 -> 10^-12





                                  share|improve this answer






















                                    up vote
                                    1
                                    down vote










                                    up vote
                                    1
                                    down vote









                                    You can do this succinctly with the ReplaceAll (/.) and Condition (/;) operators:



                                    list /. x_ /; x < 10^-12 -> 10^-12





                                    share|improve this answer












                                    You can do this succinctly with the ReplaceAll (/.) and Condition (/;) operators:



                                    list /. x_ /; x < 10^-12 -> 10^-12






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Aug 26 at 14:46









                                    Lee

                                    40817




                                    40817



























                                         

                                        draft saved


                                        draft discarded















































                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f180674%2fapplying-a-lower-bound-threshold-on-a-list%23new-answer', 'question_page');

                                        );

                                        Post as a guest













































































                                        Comments

                                        Popular posts from this blog

                                        Long meetings (6-7 hours a day): Being “babysat” by supervisor

                                        Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                                        Confectionery