IDL array subscripting issue [message #90225] |
Thu, 12 February 2015 09:22  |
David B
Messages: 18 Registered: January 2015
|
Junior Member |
|
|
Now this is probably a simple and quick problem for someone with experience. I think I may have missed the point or fallen victim to a problem with an obvious solution.
===============================
IDL> a = INDGEN(10)
IDL> b = [0,10]
IDL> print, a[b]
0 9
IDL> b = [0,9]
IDL> print, a[b]
0 9
===============================
Why?!
David B
|
|
|
|
|
|
Re: IDL array subscripting issue [message #90229 is a reply to message #90227] |
Thu, 12 February 2015 10:26   |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
On 02/12/15 12:29, Fabien wrote:
> On 12.02.2015 18:22, David B wrote:
>> ===============================
>>
>> IDL> a = INDGEN(10)
>> IDL> b = [0,10]
>> IDL> print, a[b]
>> 0 9
>> IDL> b = [0,9]
>> IDL> print, a[b]
>> 0 9
>>
>> ===============================
>> Why?!
>
> This is a strange but documented feature of IDL:
>
> http://www.exelisvis.de/docs/Using_Arrays_as_Array_Su.html
>
> See "Array Subscripts and Clipping".
>
> Depending on what you want, this is a feature of a bug. I learned to
> like it as a feature, personally.
I really like the use of negative indices to reference from the end of
the array. The above url has the following "note" in the section about
clipping:
<quote>
Note: Because of the confusion between the clipping of array subscripts
and the use of negative indices (see the next section), it is best to
avoid using code that relies on this clipping behavior.
</quote>
Just sayin'. Not judging.
cheers,
paulv
|
|
|
Re: IDL array subscripting issue [message #90230 is a reply to message #90229] |
Thu, 12 February 2015 10:36   |
Fabzi
Messages: 305 Registered: July 2010
|
Senior Member |
|
|
On 12.02.2015 19:26, Paul van Delst wrote:
>
> I really like the use of negative indices to reference from the end of
> the array. The above url has the following "note" in the section about
> clipping:
>
> <quote>
> Note: Because of the confusion between the clipping of array subscripts
> and the use of negative indices (see the next section), it is best to
> avoid using code that relies on this clipping behavior.
> </quote>
>
> Just sayin'. Not judging.
Haha, I knew this one would come, and I agree
I mean that I like the fact that array[[-1,2,3,-1]] is not throwing an
error, even before negative indices were added to IDL.
say that you're code relies on following:
inds = [-1,2,3,-1]
out = arr[inds]
p = where(inds lt 0, cnt)
if cnt ne 0 then out[p] = !VALUES.F_NAN
How would write the snipset above with
STRICTARRSUBS compile_opt?
|
|
|
Re: IDL array subscripting issue [message #90238 is a reply to message #90225] |
Fri, 13 February 2015 01:32  |
David B
Messages: 18 Registered: January 2015
|
Junior Member |
|
|
Thanks all!
The can cause issue say when you concatenate new elements onto your array upon which the index is subscripting, as then your array refernce becomes incorrect. I have just handled the case on its own and shifted the array value down to its proper value so:
index[WHERE(index EQ n_elements(array)]--
David
|
|
|