Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

Re: Setting Negatives to Zero

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82915] Re: Setting Negatives to Zero
  • From: "Kevin J. McCann" <Kevin.McCann at umbc.edu>
  • Date: Sat, 3 Nov 2007 03:26:01 -0500 (EST)
  • Organization: University System of Maryland
  • References: <fg6qha$dj0$1@smc.vnet.net> <200710311118.GAA22617@smc.vnet.net> <fgenme$g0m$1@smc.vnet.net>

What makes Clip[] fast?

Kevin

Carl Woll wrote:
> Ray Koopman wrote:
> 
>> On Oct 30, 1:38 am, "Kevin J. McCann" <Kevin.McC... at umbc.edu> 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
> 

-- 

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


  • Prev by Date: The uses of Condition (/;)
  • Next by Date: Re: Re: NumberPadding on the left
  • Previous by thread: Re: Re: Re: Setting Negatives to Zero
  • Next by thread: Re: FindRoot and Bose-Einstein distribution