Re: Re: Setting Negatives to Zero
- To: mathgroup at smc.vnet.net
- Subject: [mg82886] Re: [mg82809] Re: Setting Negatives to Zero
- From: Carl Woll <carlw at wolfram.com>
- Date: Fri, 2 Nov 2007 03:31:40 -0500 (EST)
- References: <fg6qha$dj0$1@smc.vnet.net> <200710311118.GAA22617@smc.vnet.net>
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