I want to truncate absolute values below an epsilon to 0, e.g.,
Truncate[{-3, -2, -1, 0, 1, 2, 3}, 1.5] -> {-3, -2, 0, 0, 0, 2, 3}
I guess I could write a function using Scan[] and If[], but is there a more idiomatic “one-liner” way of doing it in Mathematica?
The built in function
Chopis almost exactly what you’re looking for (it does work on lists, as in your example). One potential surprise is that it doesn’t chop (truncate) integers, only floating point numbers. So for your example to work as you might expect, first convert your list to floating point with theNfunction:As Ramashalanka shows, to do this sort of thing more generally, I recommend:
Ie, a lambda function mapped over the list.