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

Home » Public Forums » archive » Re: Absurd Indexes
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
Re: Absurd Indexes [message #9349] Fri, 20 June 1997 00:00
peter is currently offline  peter
Messages: 80
Registered: February 1994
Member
George McCabe (george.mccabe@gsfc.nasa.gov) wrote:
: R. Bauer wrote:
: >
: > b=(a(2,*))(10)

: Wow that's cool! But I'm not sure quite how to interpret the syntax.

: why do the numbers in the second pair of parenthesis refer only to the
: second dimension of the array?

They don't; they treat the array in the preceeding parentheses as a 1-D
array. Since it has dimension 1 in its first dimension, the second
subscript effective ignores it.

Peter

P.S. This kind of subscripting is very useful, esp. in expressions like
xsize = (size(variable))(1). It's not immediately obvious that it
is legal, but in fact it is.
Re: Absurd Indexes [message #9353 is a reply to message #9349] Thu, 19 June 1997 00:00 Go to previous message
George McCabe is currently offline  George McCabe
Messages: 23
Registered: June 1997
Junior Member
R. Bauer wrote:
...
> or
>
> b=(a(2,*))(0:999)
>
> In the most cases I use transpose but the second solution is very useful
> if I like to have only index 10 then it would be called:
>
> b=(a(2,*))(10)

Wow that's cool! But I'm not sure quite how to interpret the syntax.

IDL> help,b(2,*)
<Expression> INT = Array(1, 1000)
IDL> help,(b(2,*))(0:999)
<Expression> INT = Array(1000)

why do the numbers in the second pair of parenthesis refer only to the
second dimension of the array?

George

VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV VVVVVVVV
George McCabe (HSTX) NASA / GSFC
Tel: (301)286-8283, Fax: (301)286-0212 Code 693, B2 R151
E-mail: george.mccabe@gsfc.nasa.gov Greenbelt, MD 20912
Re: Absurd Indexes [message #9371 is a reply to message #9353] Wed, 18 June 1997 00:00 Go to previous message
Inigo Garcia is currently offline  Inigo Garcia
Messages: 13
Registered: June 1997
Junior Member
Sorry, I wrote it bad . As many of you guessed, what I wanted to say
was:

a=findgen(4,1000)
b=a(2,*)

Thanks for the help received.
--
\\|//
(o o)
+-----------------------oOOo-(_)-oOOo----------------------- --+
| I~nigo Garcia Ruiz |
| Kapteyn Instituut Phone: +31-(0)50-3634083 |
| Landleven 12 Fax: +31-(0)50-363 |
| 9747 AD GRONINGEN (Netherlands) e-mail: iruiz@astro.rug.nl |
+----------------------------------------------------------- --+
Re: Absurd Indexes [message #9373 is a reply to message #9371] Wed, 18 June 1997 00:00 Go to previous message
wonko is currently offline  wonko
Messages: 22
Registered: March 1997
Junior Member
iruiz@astro.rug.nl (Inigo Garcia) wrote:

> a=findgen(4,1000)
> b=fltarr(2,*)

You mean b=a(2,*) ?

> the array I get is an [1,1000] array, and I want an [1000] array !!!
> Does someone know any way of getting rid off that "1" dimension.
> (OK, I know the "for" loop method, but, there's no other method to do
> it ?)

Hmmm....... I wonder what this "for loop" method is.
The solution for your problem is using reform: b = reform( a(2,*) )

This is often annoying, but sometimes I find it useful to have arrays
like yours, eg. when dealing with 2d images. When an image has only one
plane (z dimension), I can still access it as image(x,y,z) with z eq 0.
I sometimes use reform to add even more dimensions, like
b=reform( a(2,*), 1, 1000, 1, 1 ).

But I noticed IDL behaves different. I don't have it here at home (BTW,
anyone got it to work under OS/2 Warp4 yet?), but I think b=a(*,2) would
give you an 1d array.


Alex
--
Alex Schuster Wonko@weird.cologne.de
alex@pet.mpin-koeln.mpg.de
Re: Absurd Indexes [message #9376 is a reply to message #9371] Tue, 17 June 1997 00:00 Go to previous message
meron is currently offline  meron
Messages: 51
Registered: July 1995
Member
In article <33A6A7D5.777F@astro.rug.nl>, Inigo Garcia <iruiz@astro.rug.nl> writes:
> Hi !
>
> I have a problem with some "sticky dimension in a matrix. The thing is
> that if you make something like:
>
> a=findgen(4,1000)
> b=fltarr(2,*)

You probably mean:

b = a(2,*)
>
> the array I get is an [1,1000] array, and I want an [1000] array !!!
> Does someone know any way of getting rid off that "1" dimension.

> (OK, I know the "for" loop method, but, there's no other method to do it
> ?)
>
Yeah. Use the REFORM function, i.e.

b = reform(a(2,*))

Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
Re: Absurd Indexes [message #9379 is a reply to message #9376] Tue, 17 June 1997 00:00 Go to previous message
mgs is currently offline  mgs
Messages: 144
Registered: March 1995
Senior Member
In article <5o6er7$c6j@news.orst.edu>, "Hans Luh" <luh@math.utk.edu> wrote:

> Inigo Garcia wrote in article <33A6A7D5.777F@astro.rug.nl>...
>> Hi !
>>
>> I have a problem with some "sticky dimension in a matrix. The thing is
>> that if you make something like:
>>
>> a=findgen(4,1000)
>> b=fltarr(2,*)
>>
>> the array I get is an [1,1000] array, and I want an [1000] array !!!
>> Does someone know any way of getting rid off that "1" dimension.
>> (OK, I know the "for" loop method, but, there's no other method to do it
>> ?)

Original attribution lost.
Assuming Inigo Garcia actually meant:

a=findgen(4,1000)
b=a(2, *)

Try the following to get rid of the leading dimension:
c = Reform(a(2, *))

From the IDL online help:
The REFORM function changes the dimensions of an array without changing the
total number of elements. If no dimensions are specified, REFORM returns a
copy of Array with all leading dimensions of size 1 removed.

--
Mike Schienle Interactive Visuals
mgs@sd.cybernex.net http://ww2.sd.cybernex.net/~mgs/
Re: Absurd Indexes [message #9381 is a reply to message #9376] Tue, 17 June 1997 00:00 Go to previous message
R. Bauer is currently offline  R. Bauer
Messages: 137
Registered: November 1996
Senior Member
Inigo Garcia wrote:
>
> Hi !
>
> I have a problem with some "sticky dimension in a matrix. The thing is
> that if you make something like:
>
> a=findgen(4,1000)
> b=fltarr(2,*)
>
> the array I get is an [1,1000] array, and I want an [1000] array !!!
> Does someone know any way of getting rid off that "1" dimension.
> (OK, I know the "for" loop method, but, there's no other method to do it
?)

I can help you:

try

b=transpose(a(2,*))

or

b=(a(2,*))(0:999)


In the most cases I use transpose but the second solution is very useful
if I like to have only index 10 then it would be called:

b=(a(2,*))(10)

--
R.Bauer

Institut fuer Stratosphaerische Chemie (ICG-1)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
Re: Absurd Indexes [message #9385 is a reply to message #9376] Tue, 17 June 1997 00:00 Go to previous message
Hans Luh is currently offline  Hans Luh
Messages: 1
Registered: June 1997
Junior Member
Inigo Garcia wrote in article <33A6A7D5.777F@astro.rug.nl>...
> Hi !
>
> I have a problem with some "sticky dimension in a matrix. The thing is
> that if you make something like:
>
> a=findgen(4,1000)
> b=fltarr(2,*)
>
> the array I get is an [1,1000] array, and I want an [1000] array !!!
> Does someone know any way of getting rid off that "1" dimension.
> (OK, I know the "for" loop method, but, there's no other method to do it
> ?)

I am not sure that I understand your problem correctly. However, I try

a=findgen(4,1000)

b=fltarr(2,*)



on the PV-WAVE and get

WAVE> a=findgen(4,1000)
WAVE> b=fltarr(2,*)

b=fltarr(2,*)
^
% Syntax error.


Obviously, 'b=fltarr(2,*)' is wrong. If we use size() to check the
dimensionality of a, we can find that a is a two dimensional array.

WAVE> print,size(a)
2 4 1000 4 4000

OK. If you want an one dimensional array, just use

WAVE> a=findgen(1000)
WAVE> print,size(a)
1 1000 4 1000

You now have an [1000] array.

Hans.
Re: Absurd Indexes [message #9386 is a reply to message #9376] Tue, 17 June 1997 00:00 Go to previous message
Stein Vidar Hagfors H is currently offline  Stein Vidar Hagfors H
Messages: 32
Registered: May 1997
Member
Inigo Garcia wrote:
>
> Hi !
>
> I have a problem with some "sticky dimension in a matrix. The thing is
> that if you make something like:
>
> a=findgen(4,1000)
> b=fltarr(2,*)
>
> the array I get is an [1,1000] array, and I want an [1000] array !!!

I assume you meant a(2,*), not fltarr(2,*) :-)

b = reform(a(2,*)) will do it. Reform removes singular dimensions.

Stein Vidar
Re: Absurd Indexes [message #9388 is a reply to message #9376] Tue, 17 June 1997 00:00 Go to previous message
R. Bauer is currently offline  R. Bauer
Messages: 137
Registered: November 1996
Senior Member
Inigo Garcia wrote:
>
> Hi !
>
> I have a problem with some "sticky dimension in a matrix. The thing is
> that if you make something like:
>
> a=findgen(4,1000)
> b=fltarr(2,*)
>
> the array I get is an [1,1000] array, and I want an [1000] array !!!
> Does someone know any way of getting rid off that "1" dimension.
> (OK, I know the "for" loop method, but, there's no other method to do it
>

I don't understand what you mean

if I do:

a=findgen(4,1000)
help,a
A FLOAT = Array(4, 1000)

that's correct

if I do:
b=fltarr(2,*)
^
% Syntax error.

that's correct too.



--
R.Bauer

Institut fuer Stratosphaerische Chemie (ICG-1)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: IDL UNIX->PC code compatability
Next Topic: Smooth scrolling zoom in draw widget; how?

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

Current Time: Wed Oct 08 15:53:14 PDT 2025

Total time taken to generate the page: 0.00441 seconds