comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Summer "English" heat or just me: Array slicing
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Summer "English" heat or just me: Array slicing [message #85299] Tue, 23 July 2013 08:51 Go to next message
ameigs is currently offline  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 Go to previous messageGo to next message
Fabzi is currently offline  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 Go to previous messageGo to next message
Lajos Foldy is currently offline  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 #85302 is a reply to message #85299] Tue, 23 July 2013 09:45 Go to previous messageGo to next message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
This works:

IDL> print, a[[0,3,5],[0,1], 0]
1 4 6
7 10 12

See the discussion here: https://groups.google.com/d/msg/comp.lang.idl-pvwave/Vu9rzqc kBNQ/HvkK_QnJrsgJ
Re: Summer "English" heat or just me: Array slicing [message #85312 is a reply to message #85302] Wed, 24 July 2013 06:44 Go to previous messageGo to next message
Fabzi is currently offline  Fabzi
Messages: 305
Registered: July 2010
Senior Member
On 07/23/2013 06:45 PM, Phillip Bitzer wrote:
> This works:
>
> IDL> print, a[[0,3,5],[0,1], 0]
> 1 4 6
> 7 10 12
>
> See the discussion here: https://groups.google.com/d/msg/comp.lang.idl-pvwave/Vu9rzqc kBNQ/HvkK_QnJrsgJ
>

Wow, this is another incredible newsgroup discussion that deserves to be
archived! Thanks!
Re: Summer "English" heat or just me: Array slicing [message #85313 is a reply to message #85312] Wed, 24 July 2013 06:46 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Fabien writes:

> Wow, this is another incredible newsgroup discussion that deserves to be
> archived! Thanks!

I would if I understood it. :-(

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 #85314 is a reply to message #85313] Wed, 24 July 2013 06:57 Go to previous messageGo to next message
Fabzi is currently offline  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 Go to previous messageGo to next message
David Fanning is currently offline  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 #85316 is a reply to message #85315] Wed, 24 July 2013 07:25 Go to previous messageGo to next message
Fabzi is currently offline  Fabzi
Messages: 305
Registered: July 2010
Senior Member
On 07/24/2013 04:19 PM, David Fanning wrote:
> I guess I do understand it. Sorta. I just don't want to have to explain
> it to anyone.:-)

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!
Re: Summer "English" heat or just me: Array slicing [message #85317 is a reply to message #85316] Wed, 24 July 2013 07:30 Go to previous message
David Fanning is currently offline  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.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Thickness of /box_axes?
Next Topic: Dashed linestyle in vectorized function graphics output, IDL 8.2.3

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 16:03:37 PDT 2025

Total time taken to generate the page: 0.00428 seconds