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

Home » Public Forums » archive » Re: prob. w/ subtracting scaler from an array
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: prob. w/ subtracting scaler from an array [message #10251] Wed, 05 November 1997 00:00
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Charlotte DeMott (demott@denali) uncovers an interesting
feature of IDL when she writes:

> hi, i've come across a very strange problem with IDL 5.0 and was
> wondering if anyone can find what is hopefully an obvious mistake
> that i'm overlooking. here's the scenaio:
>
> IDL> print, raw(long,*,day)
> -29.0149
> -77.3963
> IDL> x = total(pwgtd(long,*,day),2)
> IDL> print, x
> 9.79075
> IDL> print, raw(long,*,day)- x
> -38.8057
> IDL> print, raw(long,*,day)- 5
> -34.0149
> -82.3963
> i'm confused about why "raw(long,*,day) - x" returns a scalar (what
> i want is the 1D array) while "raw(long,*,day) - 5" correctly returns
> the 1D array. any ideas? thanks.

The reason for this is that x is not a scaler. It is an
array with one element in it. (Try HELP, x instead of PRINT, x).
When IDL subtracts one array from another the result is
always an array of the same size as the *smallest* array.
For example,

a = [3,5,2,6,9]
b = [4,1]
c = a - b
Help, c

C is a two-element array.

To make x a scaler, of course, you can subscript it, like this:

IDL> x = total(pwgtd(long,*,day),2)
IDL> x = x[0]

Cheers,

David

-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Numerical Recipes Article
Next Topic: plot3D and IDL cookbook

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

Current Time: Sun Oct 12 08:25:39 PDT 2025

Total time taken to generate the page: 2.23764 seconds