Strange arrary indexing quirk? [message #77182] |
Thu, 11 August 2011 18:12 |
Matt Francis
Messages: 94 Registered: May 2010
|
Member |
|
|
I stumbled across this strange behaviour:
foo = indgen(2,2)
print,foo[0,10]
< gives an error, since the second index is out of range>
however,
indx = indgen(5)
print,foo[0,indx]
0
2
2
2
2
Does anyone have any insight into why this happens? I'd expect the
second line to also throw an error. A lot of the inner workings of IDL
seem pretty arcane and hard to guess at before you try things...
I was being lazy/naughty and using a catch statement to detect when an
index went out of range, which I knew would happen very occaisonally
and was trying to avoid the performance hit of checking for it every
time. This round off instead of an error behaviour made sure that plan
didn't work!
|
|
|