MathGroup Archive 2007

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

Search the Archive

Re: Setting Negatives to Zero

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82803] Re: [mg82736] Setting Negatives to Zero
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Wed, 31 Oct 2007 06:15:16 -0500 (EST)
  • References: <7189487.1193744482274.JavaMail.root@m35> <op.t00vb4u2qu6oor@monster.gateway.2wire.net> <18551847.1193774194904.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

But Clip isn't Listable!

Attributes@Clip

{NumericFunction, Protected}

So how could that work? But it does, evidently:

Clip[Range@100, {5, 95}]

{5, 5, 5, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, \
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, \
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, \
54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, \
71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, \
88, 89, 90, 91, 92, 93, 94, 95, 95, 95, 95, 95, 95}

Yet another undocumented feature.

Bobby

On Tue, 30 Oct 2007 14:54:09 -0500, Kevin J. McCann  
<Kevin.McCann at umbc.edu> wrote:

> Thanks, Bobby.
>
> Carl Woll gave me the following way to do it.
>
> Clip[data,{0,Infinity}]
>
> It works and is fast. I had never used Clip before - actually, I didn't  
> know about it.
>
> Kevin
>
> DrMajorBob wrote:
>> data = data /. x_?Negative -> 0
>>
>> or something like
>>
>> Attributes[negToZero]={Listable}
>> negToZero[x_?NumericQ] = Sign[x] x
>> data = negToZero@data
>>
>> Bobby
>>
>> On Tue, 30 Oct 2007 03:26:37 -0500, Kevin J. McCann  
>> <Kevin.McCann 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. I know 
>>> that
>>> I will likely be embarrassed when I see how to do it, but I can't seem
>>> to remember or figure it out. I should emphasize that because of the
>>> size of the data set, this needs to be done efficiently. Another
>>> programming language does it as follows:
>>>
>>>         x(x < 0) = 0;
>>>
>>> Thanks,
>>>
>>> Kevin
>>
>>
>>
>



-- 

DrMajorBob at bigfoot.com


  • Prev by Date: Re: Re: Selecting Rows Where All Columns Satisfy a Condition-Plot of Code speeds
  • Next by Date: Re: Bug of Integrate
  • Previous by thread: Re: Setting Negatives to Zero
  • Next by thread: FindRoot and Bose-Einstein distribution