Unexpected array subscript truncation [message #68881] |
Mon, 30 November 2009 13:03 |
M. Katz
Messages: 69 Registered: May 2005
|
Member |
|
|
Here's an interesting little array trick I discovered by accident. It
doesn't give an error message where I would expect one! Try this:
* As a warm-up enter this and see that IDL does complain.
a = intarr(3,3)
a[0,5] = 1
* Now try to set it as follows, with an array of y-index values.
a[0,[0,5]] = 1
print, a
1 0 0
0 0 0
1 0 0
No complaint! In fact, IDL quietly truncated the 5 down to its highest
allowed value, which is 2.
It also works like this:
a[*,[0,9]] = 3
is equivalent to
a[*,[0,2]] = 3
The same truncation happens with x indices as well.
I suppose there could be some cases where this would not be the
desired behavior. Any thoughts? Am I missing something?
-M.
|
|
|