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

Home » Public Forums » archive » help with - count in where() function
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
help with - count in where() function [message #90868] Thu, 30 April 2015 10:32 Go to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
Hi

I wrote a simple example of my code to understand the behaviour of count in the where() function but I still don't understand something.

My example:

array = [[-1,2,3,4,5],[6,-7,8,9,10]]
mask =bytarr(5,5)
for i=0L,4 do begin
for j=0L, 4 do begin
IF (TOTAL(ARRAY GT 5.)+ TOTAL(Array LT 0.)) EQ 0 THEN mask[i,j]=1
endfor
endfor

ind = where(mask EQ 1,count)
print, count
IDL> 0


print, total(array GT 5.)
> IDL 4.00000
print, total(array LT 0.)
> IDL 2.00000


I was expecting the answers in the two last prints. I don't understand why when I print out the count it's zero. Can anyone help?

Actually I was expecting to be 4 because there are 2 negatives and 4 greater than 5 so (2+4=6, thus 10-6=4).

Thanks
Re: help with - count in where() function [message #90869 is a reply to message #90868] Thu, 30 April 2015 10:58 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
On 04/30/15 13:32, g.nacarts@gmail.com wrote:
> Hi
>
> I wrote a simple example of my code to understand the behaviour of
count in the where() function but I still don't understand something.
>
> My example:
>
> array = [[-1,2,3,4,5],[6,-7,8,9,10]]
> mask =bytarr(5,5)
> for i=0L,4 do begin
> for j=0L, 4 do begin
> IF (TOTAL(ARRAY GT 5.)+ TOTAL(Array LT 0.)) EQ 0 THEN mask[i,j]=1
> endfor
> endfor
>
> ind = where(mask EQ 1,count)
> print, count
> IDL> 0
>
>
> print, total(array GT 5.)
>> IDL 4.00000
> print, total(array LT 0.)
>> IDL 2.00000
>
>
> I was expecting the answers in the two last prints. I don't
> understand
why when I print out the count it's zero. Can anyone help?
>
> Actually I was expecting to be 4 because there are 2 negatives and 4
greater than 5 so (2+4=6, thus 10-6=4).

Umm....but you're asking to set the mask element if 4+2 = 0.

Last time I checked, 4+2 never equals 0 (in this universe at least) so
no mask elements will ever be set to 1.

Maybe your TOTAL() commands require some additional info re the i or j
indices?

Or am I being brain dead here?

cheers,

paulv
Re: help with - count in where() function [message #90872 is a reply to message #90868] Fri, 01 May 2015 07:33 Go to previous message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
On Thursday, April 30, 2015 at 12:32:32 PM UTC-5, g.na...@gmail.com wrote:
> Hi
>
> I wrote a simple example of my code to understand the behaviour of count in the where() function but I still don't understand something.
>
> My example:
>
> array = [[-1,2,3,4,5],[6,-7,8,9,10]]
> mask =bytarr(5,5)
> for i=0L,4 do begin
> for j=0L, 4 do begin
> IF (TOTAL(ARRAY GT 5.)+ TOTAL(Array LT 0.)) EQ 0 THEN mask[i,j]=1
> endfor
> endfor
>
> ind = where(mask EQ 1,count)

>
> I was expecting the answers in the two last prints. I don't understand why when I print out the count it's zero.

Why do expect that to be the answer? Look at your loop again:

> for i=0L,4 do begin
> for j=0L, 4 do begin
> IF (TOTAL(ARRAY GT 5.)+ TOTAL(Array LT 0.)) EQ 0 THEN mask[i,j]=1
> endfor
> endfor

When, i=0, j=0, the total of `array GT 5` is 4 and the total of `array LT 0` is two.
When i=0, j=1, the total of `array GT 5` is 4 and the total of `array LT 0` is two.
When i=0, j=2, the total of `array GT 5` is 4 and the total of `array LT 0` is two.

See a pattern? ;-)

So, TOTAL(ARRAY GT 5.)+ TOTAL(Array LT 0.)) is never 0, as PaulV said.

Now, what exactly is the problem you're trying to solve?
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Copying contents of a function graphics window
Next Topic: Mapping southern in Northern map

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

Current Time: Wed Oct 08 07:24:13 PDT 2025

Total time taken to generate the page: 0.00432 seconds