I'd like to replace all values in a list which obey one or more criteria with another value. Example: Replace all values>30 by 30.
data={{3,35},{2,7}}
afterwards it should be
{{3,30},{2,7}}
|
I'd like to replace all values in a list which obey one or more criteria with another value. Example: Replace all values>30 by 30.
afterwards it should be
|
||||
| show 7 more comments |
|
I couldn't find a question that is an exact duplicate of this one. Up front you have a choice between pattern-based and numeric manipulation of an array. Pattern-based is more general; numeric is usually fastest when applicable.
Examples of pattern based methods:
Examples of numeric methods:
Other, less desirable methods:
|
|||||||
|
|
data /. x_ /; x > 30 -> 30? – b.gatessucks Aug 22 '12 at 13:19Clip[{{3, 35}, {2, 7}}, {-Infinity, 30}]– Yves Klett Aug 22 '12 at 13:26data /. x_ -> Min[x, 30]. – 0x4A4D♦ Aug 22 '12 at 13:26