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 
Return to the default flat view Create a new topic Submit Reply
Re: Ternary Operator for Arrays [message #39531] Tue, 25 May 2004 14:00 Go to previous 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
[Message index]
 
Read Message
Read Message
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: Fri Oct 10 05:28:17 PDT 2025

Total time taken to generate the page: 0.85273 seconds