MathGroup Archive 2007

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

Search the Archive

Re: Re: Setting Negatives to Zero

  • To: mathgroup at
  • Subject: [mg82886] Re: [mg82809] Re: Setting Negatives to Zero
  • From: Carl Woll <carlw at>
  • Date: Fri, 2 Nov 2007 03:31:40 -0500 (EST)
  • References: <fg6qha$dj0$> <>

Ray Koopman wrote:

>On Oct 30, 1:38 am, "Kevin J. McCann" <Kevin.McC... at> wrote:
>>I have a very large data set (64000 x 583) in which negative values
>>indicate "no data", unfortunately these negatives are not all the same.
>>I would like to efficiently set all these negatives to zero.
>With 10% of data missing,  data*UnitStep[data]
>is about twice as fast as  data/._?Negative->0
>for real data, and about 30 times as fast for integer data.
The reason data*UnitStep[data] is slow for real data is because real * 1 
is a real number, while real * 0 is an integer. If UnitStep[data] has a 
mixture of 0s and 1s, then unpacking of packed arrays will occur when 
evaluating data*UnitStep[data]. To avoid this unpacking you could use 
data*N[UnitStep[data]], which will be much faster, although not as fast 
as using Clip.

Carl Woll
Wolfram Research

  • Prev by Date: Re: Rotating TreePlot
  • Next by Date: Re: NDSolve with functions of vectors
  • Previous by thread: Re: Re: Setting Negatives to Zero
  • Next by thread: Re: Setting Negatives to Zero