I have a list with some values and I want to replace a value which is greater than 1 with 1 otherwise keep the value. In this case 10562:
list[[1]]= {0.61975, 10562., 0.43274, 0.15068, 0.13703, 0.057564}
I tried this approach:
Table[If[list[[1, x]] > 1, list[[1, x]] = 1, list[[1, x]]], {x,
1, Length[list[[1]]]}]
It works, but I'm wondering if there is a much simpler solution with mathematica. Can anybody help me out?
Answer
Use Clip
:
Clip[{0.61975, 10562., 0.43274, 0.15068, 0.13703, 0.057564}, {-Infinity, 1}]
{0.61975, 1, 0.43274, 0.15068, 0.13703, 0.057564}
Comments
Post a Comment