comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Ternary Operator for Arrays
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Ternary Operator for Arrays [message #39531] Tue, 25 May 2004 14:00 Go to next message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Tue, 25 May 2004 12:07:18 -0700, Jack Yin wrote:

> Does anyone know of a good clean way of doing ternary operation on
> arrays without using FOR loops and nested IF statements?
>
> For example, I have three arrays A, B and C and I want to do A = B /
> C, but there are elements in C that are zeros and I want to set the
> corresponding elements in A to zeros without actually doing the
> division to avoid divide by zero error. The ternary operator (?:)
> only works on scalers. Is there something comparable for arrays?
>
> Any help would be greatly appreciated!

A couple of ways, not necessarily clean:

For integers or floats:

a=b/(c eq 0 + c*(d=c ne 0))*d

For positive floats:

a=b/(c>(machar()).xmin)*c ne 0.0


JD
Re: Ternary Operator for Arrays [message #39606 is a reply to message #39531] Wed, 26 May 2004 08:32 Go to previous message
jack.c.yin is currently offline  jack.c.yin
Messages: 5
Registered: January 2004
Junior Member
JD Smith <jdsmith@as.arizona.edu> wrote in message news:<pan.2004.05.25.21.00.07.321890@as.arizona.edu>...
> On Tue, 25 May 2004 12:07:18 -0700, Jack Yin wrote:
>
>> Does anyone know of a good clean way of doing ternary operation on
>> arrays without using FOR loops and nested IF statements?
>>
>> For example, I have three arrays A, B and C and I want to do A = B /
>> C, but there are elements in C that are zeros and I want to set the
>> corresponding elements in A to zeros without actually doing the
>> division to avoid divide by zero error. The ternary operator (?:)
>> only works on scalers. Is there something comparable for arrays?
>>
>> Any help would be greatly appreciated!
>
> A couple of ways, not necessarily clean:
>
> For integers or floats:
>
> a=b/(c eq 0 + c*(d=c ne 0))*d
>
> For positive floats:
>
> a=b/(c>(machar()).xmin)*c ne 0.0
>
>
> JD

JD,

Thanks for the tips. They will work for me. Really appreciate the help!

Jack
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: accessing data from READ_ASCII
Next Topic: Projection of an emissivity cube

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:25:44 PDT 2025

Total time taken to generate the page: 0.00588 seconds