Summer "English" heat or just me: Array slicing [message #85299] |
Tue, 23 July 2013 08:51  |
ameigs
Messages: 12 Registered: March 2009
|
Junior Member |
|
|
I'm betting this is too easy, but having been away from my work computer for several weeks I think dementia has set in:
Here's a simple array:
IDL> a = [[1,2,3,4,5,6],[7,8,9,10,11,12]]
IDL> help, a
A INT = Array[6, 2]
IDL> print, a
1 2 3 4 5 6
7 8 9 10 11 12
I want to get just the indices of dim 0 and dim 1 I need from a list of indices. So I tried this:
IDL> print, a[[0,3,5],[0]]
% All array subscripts must be same size. Var = A
But this works
IDL> print, a[[0,3,5],0]
1 4 6
IDL> print, a[[0,3,5],1]
7 10 12
IDL>
IDL> print, a[[0,3,5],0:1]
1 4 6
7 10 12
IDL>
And this does not:
IDL> print, a[[0,3,5],[0,1]]
% All array subscripts must be same size. Var = A
% Execution halted at: $MAIN$
What have I forgotten?
Andy
|
|
|
Re: Summer "English" heat or just me: Array slicing [message #85300 is a reply to message #85299] |
Tue, 23 July 2013 09:12   |
Fabzi
Messages: 305 Registered: July 2010
|
Senior Member |
|
|
On 07/23/2013 05:51 PM, ameigs wrote:
> What have I forgotten?
That what you want could have another meaning in IDL. Try this:
IDL> print, a[[0,3,5],[0,1,0]]
But this will do what you want:
IDL> print, a[[0,3,5]#[1,1],[0,1]##[1,1,1]]
I don't know if there is another solution.
Cheers,
Fab
|
|
|
Re: Summer "English" heat or just me: Array slicing [message #85301 is a reply to message #85299] |
Tue, 23 July 2013 09:16   |
Lajos Foldy
Messages: 176 Registered: December 2011
|
Senior Member |
|
|
On Tuesday, July 23, 2013 5:51:10 PM UTC+2, ameigs wrote:
> I'm betting this is too easy, but having been away from my work computer for several weeks I think dementia has set in:
>
>
>
> Here's a simple array:
>
> IDL> a = [[1,2,3,4,5,6],[7,8,9,10,11,12]]
>
> IDL> help, a
>
> A INT = Array[6, 2]
>
> IDL> print, a
>
> 1 2 3 4 5 6
>
> 7 8 9 10 11 12
>
>
>
> I want to get just the indices of dim 0 and dim 1 I need from a list of indices. So I tried this:
>
> IDL> print, a[[0,3,5],[0]]
>
> % All array subscripts must be same size. Var = A
>
>
>
> But this works
>
> IDL> print, a[[0,3,5],0]
>
> 1 4 6
>
> IDL> print, a[[0,3,5],1]
>
> 7 10 12
>
> IDL>
>
> IDL> print, a[[0,3,5],0:1]
>
> 1 4 6
>
> 7 10 12
>
> IDL>
>
> And this does not:
>
> IDL> print, a[[0,3,5],[0,1]]
>
> % All array subscripts must be same size. Var = A
>
> % Execution halted at: $MAIN$
>
>
>
> What have I forgotten?
>
>
>
> Andy
If all subscripts are array subscripts, then their sizes must be equal.
regards,
Lajos
|
|
|
|
|
|
Re: Summer "English" heat or just me: Array slicing [message #85314 is a reply to message #85313] |
Wed, 24 July 2013 06:57   |
Fabzi
Messages: 305 Registered: July 2010
|
Senior Member |
|
|
On 07/24/2013 03:46 PM, David Fanning wrote:
> I would if I understood it. :-(
This is what you said 14 years ago ;-)
I think I understood this part:
;-Quoting Henry Chapman----------------------------------------------
There are two behaviours you may want when you try result = array[x,
y,..., z], and x, y, ..., z are 1-d arrays:
1. return a 1-d array with result[i] = array[x[i], y[i],..., z[i]]
2. return a 2-d array with result[i, j,..., k] = array[x[i],
y[j],...,z[k]]
IDL does (1), which requires x, y,...,z all have the same length.
However, IDL does (2) if one of the dimensions is a subscript range.
Since a single number is a subscript range, it will do (2) in that
case. And since 0, written in as an extra dimension is also a subscript
range, IDL will use behaviour (2)
;----------------------------------------------------------- --------
I must admit that I am only really rarely confronted to cases where I
can use this, but it is good to know...
|
|
|
Re: Summer "English" heat or just me: Array slicing [message #85315 is a reply to message #85314] |
Wed, 24 July 2013 07:19   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Fabien writes:
> This is what you said 14 years ago ;-)
Sigh... My life wasted.
> I think I understood this part:
>
> ;-Quoting Henry Chapman----------------------------------------------
>
> There are two behaviours you may want when you try result = array[x,
> y,..., z], and x, y, ..., z are 1-d arrays:
>
> 1. return a 1-d array with result[i] = array[x[i], y[i],..., z[i]]
> 2. return a 2-d array with result[i, j,..., k] = array[x[i],
> y[j],...,z[k]]
>
> IDL does (1), which requires x, y,...,z all have the same length.
> However, IDL does (2) if one of the dimensions is a subscript range.
> Since a single number is a subscript range, it will do (2) in that
> case. And since 0, written in as an extra dimension is also a subscript
> range, IDL will use behaviour (2)
> ;----------------------------------------------------------- --------
>
> I must admit that I am only really rarely confronted to cases where I
> can use this, but it is good to know...
I think this has to do with an "index threading" article JD wrote,
although I can't find a reference to it right now.
I guess I do understand it. Sorta. I just don't want to have to explain
it to anyone. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
|
Re: Summer "English" heat or just me: Array slicing [message #85317 is a reply to message #85316] |
Wed, 24 July 2013 07:30  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Fabien writes:
> This would be a good moment for Mark or Chris to jump in and indicate us
> the right page of the IDL documentation where this behaviour is described!
Well, the deed was done well before their time. It would be like trying
to explain how the Contour procedure works. Who knows!? No one in their
right mind would look into it now. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|