# Keep zero values using GaussianFilter[ ]?

Posted 1 month ago
447 Views
|
5 Replies
|
6 Total Likes
|
 Hi,Is there a way to preserve zero values when we use a filter command? data = {12.76, 7.68, 13.85, 4.5, 2.32, 3.64, 2.18, 2.72, 1.62, 0.0, 18.09, 12.28, 18., 9.76, 8.16, 0.0, 21.41, 0.53, 4.7, 0.81, 11.44, 4.36, 15.58, 20.17, 7.48, 3.67, 2.73, 8.66, 4.82, 0.84, 4.04, 39.19, 0.18, 1.76, 3.35, 10.79, 11.85, 7.1, 0.58, 2.84, 3.68}; GraphicsRow[{ListLinePlot[data], ListLinePlot[GaussianFilter[data, 1.5], PlotRange -> All]}] 
5 Replies
Sort By:
Posted 1 month ago
 Dear Mohammad,I guess it depends on what you basically want to achieve using GaussianFilter. A very simple way to preserve the zeros would be to use the respective minimum of the data and the filtered data: filteredData = GaussianFilter[data, 1.5]; mindata = Min /@ Transpose[{data, filteredData}]; ListLinePlot[{data, filteredData, mindata}, PlotStyle -> {Dashed, Black, {Thick, Red}}, PlotRange -> All, ImageSize -> Large] Regards -- Henrik
Posted 1 month ago
 Or if you want to preserve only the zero values GaussianFilter[data, 1.5] // ReplacePart[#, Position[data, 0.0] -> 0.0] & 
Posted 1 month ago
 Thank you so much, Henrik and Rohit.
 You could record zeros, apply a gaussian filter, than replace the areas in the dataset which were previously zeros. Isn't that the same as this from my answer? GaussianFilter[data, 1.5] // ReplacePart[#, Position[data, 0.0] -> 0.0] & `