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

Home » Public Forums » archive » N_ELEMENTS and WHERE: Scalar or Array ?
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: N_ELEMENTS and WHERE: Scalar or Array ? [message #14206 is a reply to message #14130] Mon, 01 February 1999 00:00 Go to previous messageGo to previous message
wmc is currently offline  wmc
Messages: 117
Registered: February 1995
Senior Member
Stein Vidar Hagfors Haugan <steinhh@ulrik.uio.no> wrote:
> In article <36b57934.0@news.nwl.ac.uk> wmc@bas.ac.uk writes:
>> But since this has come up, & its one of my pet peeves: why cannot where
>> return a null array to indicate no-elements-match. And then array[null] would
>> match to nothing. This would allow one to say
>>
>> array[where(wurble)]='stoat'
>>

> I agree, it would be a nice feature... However, I have problems
> seeing how to implement this, without altering e.g. the way IDL
> allows you to index arrays with an array that is out of
> bounds.. (try help,(findgen(10))(findgen(20)-5))

I'm not sure this is so: indexing by nulls ("where" in the example
above would return "null", not -1) can be distinguished from out-
of-range.

But even so: I've always felt that allowing
indexing by out of bounds indices is more a bug that a feature. Why
is it possible? Can you think of an example where it is useful, or
necessary?

If this is necessary for legacy reasons, it might be possible to make
() and [] behave differently in this case? Possibly a missed
opportunity when [] came in!

> Maybe using (float/double) NaN values? Hmm. That could work!
> Let's see,

> array[NaN] = 5 ; Would be allowed, but does nothing

This could well be possible as an easy-to-do work-around. In that
case, where would have to return NaN not -1.

The other possibility (which would only work for this special case,
but its quite a common special case) is that -1 would count as a
"special" value & assigning to array[-1] would, as a special case,
just do nothing rather than producing an error message.

Incidentally, I've just realised how dangerous the out-of-bounds stuff
is:

array([where(array eq false)])='stoat'

assigns to the first element...

>> While I'm here: would RSI please put a decent regexp package into IDL?

> Take a look at http://www.uio.no/~steinhh/IDL/additions.html for an
> example of how to add it using dynamically loadable modules.
> It requires a Unix flavor with regex.h

I have that so I'll take a look. Thanks!

-W.

--
William M Connolley | wmc@bas.ac.uk | http://www.nbs.ac.uk/public/icd/wmc/
Climate Modeller, British Antarctic Survey | Disclaimer: I speak for myself
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Scalp editting??
Next Topic: Map spanning Dateline?

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

Current Time: Thu Oct 09 20:39:48 PDT 2025

Total time taken to generate the page: 0.56108 seconds