Re: Array index for arrays [message #28335] |
Tue, 04 December 2001 06:35  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
the_cacc@hotmail.com (trouble) writes:
> z=indgen(4,4)
> ix=[0,1]
> help,z[ix,ix]
>
> <Expression> INT = Array[2]
...
> Not what I expected !?!
Yes, this has burned me a couple of times. The short answer is that
when you combine two or more "index lists", then they are treated as
one-for-one coordinate lists. What you want can be achieved in two
separate indexing steps:
help, (z[ix,*])[*,iy]
Ie, first do the X index then the Y index.
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: Array index for arrays [message #28417 is a reply to message #28335] |
Tue, 04 December 2001 18:40  |
air_jlin
Messages: 22 Registered: July 2001
|
Junior Member |
|
|
Craig Markwardt <craigmnet@cow.physics.wisc.edu> wrote in message
news:<onr8qb6ok2.fsf@cow.physics.wisc.edu>...
> [...]
>
> Yes, this has burned me a couple of times. The short answer is that
> when you combine two or more "index lists", then they are treated as
> one-for-one coordinate lists. What you want can be achieved in two
> separate indexing steps:
>
but how come adding a third "*" dimension gives something you would
expect?
---------------------------------
IDL> z=indgen(3,2,4)
IDL> ix=[0,1]
IDL> print,z
0 1 2
3 4 5
6 7 8
9 10 11
12 13 14
15 16 17
18 19 20
21 22 23
IDL> print,z[ix,ix,*]
0 1
3 4
6 7
9 10
12 13
15 16
18 19
21 22
---------------------------------
thanks!
best,
-Johnny
-------------------------------------------
Johnny Lin
CIRES, University of Colorado
Work Phone: (303) 735-1636
Web: http://cires.colorado.edu/~johnny/
-------------------------------------------
|
|
|