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

Home » Public Forums » archive » Re: Array to Scalar
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: Array to Scalar [message #4929] Thu, 24 August 1995 00:00
hahn is currently offline  hahn
Messages: 108
Registered: November 1993
Senior Member
sanjay@windvane.umd.edu (Sanjay K) wrote:

> I noticed, accidentally, that the multiplication of an array
> by a scalar and multiplication of an array by an array of length 1
> gives two different answers. Even though this is to be expected
> for general arrays, there needs to be an exception for array of
> size 1.

[Example deleted]

> -sanjay

What does IDL when a binary (two sided) operation of arrays of
different length is requested ?

a = [ 1, 2, 3, 4 ]
b = [ 5, 6 ]
help, a*b
EXPRESSION INT = ARRAY(2)

Obviousliy IDL starts to multiply the arrays element by element
until the shorter array is exhausted. Then the operation terminates.
Thus, if one array is only one element in size, the result will only
receive one element.

There is a big difference between one array element and a skalar
variable:

* Using an array element as argument of a procedure call
prevents you to change its value! Thus, you cannot read into
an array element.

* Using x(*,5) in an expression will be interpreted as a matrix
rather than a vector. While the assignment a = x(*,5)
REFORMats this expression to a vector!

You can probably find more expamples when digging the manual,
this is what just came into my mind...

Norbert Hahn
Re: Array to Scalar [message #4937 is a reply to message #4929] Wed, 23 August 1995 00:00 Go to previous message
afl is currently offline  afl
Messages: 51
Registered: December 1994
Member
In article <41fg1d$69h@mojo.eng.umd.edu>, sanjay@windvane.umd.edu (Sanjay K)
writes:
|> I noticed, accidentally, that the multiplication of an array
|> by a scalar and multiplication of an array by an array of length 1
|> gives two different answers. Even though this is to be expected
|> for general arrays, there needs to be an exception for array of
|> size 1.
|>
|> Consider the following example:
|>
|> a=findgen(10)
|> ; unrelated code
|> factor=interpol(....)
|>
|> factor returns array of size 1 and if I use
|>
|> a=a*factor
|>
|> I am left with just one value whereas I expect
|> an array of size 10 each of the elments multiplied by factor!
|>
|> My 2 cents worth!.

Yes. This is the exact behavior one should expect.
Maybe you wish to perform a matrix multiply.

IDL> a = findgen(10)
IDL> factor= fltarr(1) + 2.0 ; Assign 2.0 to factor vector
IDL> d = a # factor
IDL> help, d
IDL> print, d

Andy Loughe
afl@cdc.noaa.gov
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Query: How to import Color Tables
Next Topic: MachTen and IDL

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

Current Time: Fri Oct 10 05:21:22 PDT 2025

Total time taken to generate the page: 0.63794 seconds