Applying a lower bound threshold on a list
Clash 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
list-manipulation
add a comment |Â
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
list-manipulation
add a comment |Â
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
list-manipulation
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
list-manipulation
asked Aug 26 at 9:20
jarhead
689412
689412
add a comment |Â
add a comment |Â
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
add a comment |Â
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!
add a comment |Â
up vote
1
down vote
You can do this succinctly with the ReplaceAll (/.)
and Condition (/;)
operators:
list /. x_ /; x < 10^-12 -> 10^-12
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
edited Aug 26 at 10:43
answered Aug 26 at 9:32
kglr
158k8183382
158k8183382
add a comment |Â
add a comment |Â
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!
add a comment |Â
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!
add a comment |Â
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!
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!
answered Aug 26 at 9:37
Alexei Boulbitch
20.3k2368
20.3k2368
add a comment |Â
add a comment |Â
up vote
1
down vote
You can do this succinctly with the ReplaceAll (/.)
and Condition (/;)
operators:
list /. x_ /; x < 10^-12 -> 10^-12
add a comment |Â
up vote
1
down vote
You can do this succinctly with the ReplaceAll (/.)
and Condition (/;)
operators:
list /. x_ /; x < 10^-12 -> 10^-12
add a comment |Â
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
You can do this succinctly with the ReplaceAll (/.)
and Condition (/;)
operators:
list /. x_ /; x < 10^-12 -> 10^-12
answered Aug 26 at 14:46
Lee
40817
40817
add a comment |Â
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%2f180674%2fapplying-a-lower-bound-threshold-on-a-list%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