MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: What is the fastest way to threshold data?

  • To: mathgroup at
  • Subject: [mg85931] Re: What is the fastest way to threshold data?
  • From: "Kevin J. McCann" <Kevin.McCann at>
  • Date: Thu, 28 Feb 2008 02:45:56 -0500 (EST)
  • Organization: University System of Maryland
  • References: <fq3af1$fot$>

Thanks to Carl Woll, Sseziwa Mukasa, Valeri Astanoff, and Bob Hanlon for 
responding to my query. I looked at each and they all work as expected, 
of course. The fastest is the suggestion due to Carl to use Clip:

threshold = 0.75;
data = RandomReal[{-1, 1}, {1000000, 3}];
Timing[data[[All, 3]] = Clip[data[[All, 3]], {threshold, Infinity}];]

This runs in about 0.1s on my computer and is at least 10 times faster 
than the others. Thanks again.


Kevin J. McCann wrote:
> I have some 3d data {{x1,y1,z1},{x2,y2,z2},...} and I would like to set 
> the z-values to zero if they fall below zero. More generally, I would 
> like to set z to a threshold value if it is at or below a threshold. 
> This seems as though it should be an easy enough thing to do, but the 
> only way I have figured out is to parse out the z-vector, do
> mask=((#<thresh&) /@ zdata)/.True->0/.False->1;
> then
> zvector = zvector*mask;
> and rebuild the {x,y,z} data.
> Kevin


Kevin J. McCann
Research Associate Professor
Physics Building
University of Maryland, Baltimore County
1000 Hilltop Circle
Baltimore, MD 21250

  • Prev by Date: Re: Using Fourier and InverseFourier instead of Convolve
  • Next by Date: RE: Text does not scale with size of graphic
  • Previous by thread: Re: What is the fastest way to threshold data?
  • Next by thread: Efficiency and ReplacePart?