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

Home » Public Forums » archive » Re: extracting values from an 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: extracting values from an array [message #44280 is a reply to message #44279] Wed, 01 June 2005 11:58 Go to previous message
R.G. Stockwell is currently offline  R.G. Stockwell
Messages: 363
Registered: July 1999
Senior Member
"Francois L." <fleduc@lycos.com> wrote in message
news:1117651509.818205@news.drenet.dnd.ca...
> Hello,
>
> Probably a simple question...
>
> I have an array A and I want to extract values greater than -1.
>> A = [2,-1, -1, 3,-1,-1, 4, -1]
>> w = where(a gt -1)
>> if w[0] gt -1 then b = a[w]
>
> Is there a cleaner and faster way to do this ?
>
> Thanks,
>
> Fran�ois.


Hi,

cleaner? I doubt it, I think where() is pretty clean :) and I don't think
writing
two lines of code is being excessively verbose.

faster? you could try a histogram call, with the reverse indices keyword,
since histogram is a magic routine that, when used non-intuitively,
usually leads to superior results. Use 2 bins, -1000 to -1, and 0 to 1000
for
instance, where 1000 is chosen to be larger than any of your data.
This may be less clean than the where() call.

If, however, you are looping through a large number of A vectors,
perhaps you could do a histogram call on all of them (or something like
that).
Or if you are looping over different criteria (gt -1, then gt 1, etc) that
could
be accomplished in one histogram call.

Exactly how big is this A array that you are not satisfied with the speed of
where?

Cheers,
bob
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Python reader for IDL save files.
Next Topic: GUI states

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

Current Time: Thu Oct 09 07:48:01 PDT 2025

Total time taken to generate the page: 3.44167 seconds