MathGroup Archive 2007

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

Search the Archive

Re: Re: Re: Setting Negatives to Zero

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82885] Re: [mg82868] Re: [mg82803] Re: [mg82736] Setting Negatives to Zero
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Fri, 2 Nov 2007 03:31:09 -0500 (EST)
  • References: <7189487.1193744482274.JavaMail.root@m35> <op.t00vb4u2qu6oor@monster.gateway.2wire.net> <18551847.1193774194904.JavaMail.root@m35> <200710311115.GAA22532@smc.vnet.net> <17638898.1193968084061.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

OK, you got me, I meant "FirstListable" or something like that.

Man, I feel foolish!

Bobby

On Thu, 01 Nov 2007 05:25:32 -0500, Andrzej Kozlowski <akoz at mimuw.edu.pl>  
wrote:

> But Clip could not be possibly be listable (i.e. there is no need to
> check its attributes to know that). Note that a listable function
> does this:
>
> SetAttributes[f, Listable]
> f[{a, b}, {c, d}]
> {f(a, c), f(b, d)}
>
> So if you try to make Clip Listable you will get in to serious trouble:
>
> SetAttributes[Clip, Listable]
>
>   Clip[{4,5},{2,3}]
> Clip::rtwo: The argument 2 at position 2 is expected to be a list of
> a lower clip bound and an upper clip bound. >>
> Clip::rtwo: The argument 3 at position 2 is expected to be a list of
> a lower clip bound and an upper clip bound. >>
> {Clip(4,2),Clip(5,3)}
>
> On the other hand, you seem to be right that the feature in question
> (which is not Listability) is not documented.
>
> Andrzej Kozlowski
>
>
> On 31 Oct 2007, at 20:15, DrMajorBob wrote:
>
>> 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
>>
>
>
>



-- 

DrMajorBob at bigfoot.com


  • Prev by Date: Re: ReadList -- file size limits?
  • Next by Date: Re: Converting a number back to a symbol?
  • Previous by thread: Re: Setting Negatives to Zero
  • Next by thread: Re: Setting Negatives to Zero