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

Home » Public Forums » archive » Re: Padding arrays - vector subscripts not working
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: Padding arrays - vector subscripts not working [message #71584 is a reply to message #71583] Fri, 02 July 2010 12:29 Go to previous messageGo to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Jul 2, 3:51 pm, James <donje...@gmail.com> wrote:
> Well, I see that this was already asked by hradliv in 2007 and
> answered by JD Smith, among others.  Still, it seems strange that the
> natural method I tried to use doesn't work.

It is not strange.

X[1,1,1] = Y

and

X[diff] = Y with diff=[1,1,1]

are different things. X[diff] is the same as X[[1,1,1]].

To see the difference, consider this case (where I defined X so that
its elements are not all equal)

IDL> X = bindgen(5,5,5)

IDL> print,X[1,1,1]
31
IDL> print,X[31]
31

Both of these print lines are accessing the same (one) element of X,
the one at the (3D) indexes 1,1,1, which, as it happens, is the 32nd
element of the array:

IDL> print,array_indices(X,31)
1 1 1

Now,

IDL> diff=[1,1,1]
IDL> print,X[diff]
1 1 1

X[diff], which is the same as X[[1,1,1]], is a 3-element array, where
each element has the element of X with the (1D) index 1, that is, this
is 3 copies of the second element of X:

IDL> print,array_indices(X,1)
1 0 0
IDL> print,X[1,0,0]
1

X[diff] is the same as X[1,0,0], repeated 3 times.

Now, looking at your assignments:

X[1,1,1]=Y

is assigning 12 elements of X (Y has 12 elements), sequentially,
starting at X[1,1,1]. Which is working only because X has 125
elements, and this assignment is using 12 elements, starting at the
32nd, thus it fits inside X (it is assigning from to the 32nd to the
43rd element of X the 12 values in Y)

X[diff], since it is X[[1,1,1]] is attempting to assign the 12 values
of Y into 3 values (since X[[1,1,1]] is a 3-element array), thus it
fails. Only if you tried to assign to X[diff] a 3-element array (or a
scalar, which would be repeated), would this have worked.

If this is seeming too abstract, redo these examples with small 2D
arrays (which print nicely), and look at the whole X array, and how it
changes after assignments.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: How to exchange data in multi-top-level base widgets?
Next Topic: Re: REGRESS and sky background

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

Current Time: Wed Oct 08 19:31:54 PDT 2025

Total time taken to generate the page: 0.00257 seconds