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

Home » Public Forums » archive » Re: array transpose
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: array transpose [message #8773] Tue, 22 April 1997 00:00
Joseph M Zawodny is currently offline  Joseph M Zawodny
Messages: 24
Registered: March 1996
Junior Member
This is a multi-part message in MIME format.

--------------17601F1B6C24
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

David Fanning wrote:
>
> Christian Soeller <csoelle@sghms.ac.uk> writes:
>
>> Gary Fu <gfu@shark.gsfc.nasa.gov> writes:
>>
>>>>
>>>> RTFM -> transpose function
>>>>
>>>> Christian
>>>
>>> The TRANSPOSE function will transpose to array(Z,Y,X), not array(Y,X,Z).
>>
>> And what about transpose(array,[1,0,2]) ?
>> As I said, it's in the manual; one obviously has to know how to read it ;).
>
> What manual are you reading, Christian? Or perhaps more to the point,
> exactly HOW are you reading it!? I don't find this is *my* manual. :-(
>
> In any case, I can't get this to work. Can you perhaps tell us what
> software you are using and give us a simple example.
>
> Thanks,
>
> David

I hope that my attachment appears below. I have written an
n-dimensional
transpose that, while not pretty or fast, does work.

Have fun,

JMZ

--------------17601F1B6C24
Content-Type: text/plain; charset=us-ascii; name="reindex.pro"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="reindex.pro"

;+
; Name: REINDEX
; Purpose: reorder the array subscripts, an n-dimensional transpose.
; Category: Array manipulation
; Calling sequence: out_arr=REINDEX(in_arr, sort)
; or out_arr=REINDEX(/help)
;
; Example: if IN_ARR = intarr(2,3,4,5) then
; out_arr = reindex(in_arr,[2,4,3,1]) results in
; out_arr becomming an array of dimension intarr(3,5,4,2)
; or reindex( f(x,y,z),[2,3,1]) becomes f(y,z,x)
; or reindex( f(x,y,z),[1,2,3]) does nothing
;
; Inputs:
; IN_ARR n-dimensional array 1 < n < 8
; SORT vector listing order of subscripts in result
; KEYWORDS"
; /HELP Informs the user about this proceedure
;
; Output:
; OUT_ARR n-dimensional array 1 < n < 8 of same type as IN_ARR
; with subscripts reordered
;
; Optional output parameters: None
; Common blocks: None
; Side Effects: None
; Restrictions: Very large arrays may cause
; excessive page faulting
; Routines used: None
; Procedure: Straight foreward.
; Modification history:
; V-1.0 First "Public release"
; Oct 15, 1990 J.M. Zawodny, NASA LaRC
;-
function REINDEX,a,ind_order,help=help

if keyword_set(help) then begin
print,' '
print,' Name: REINDEX'
print,' Purpose: reorder the array subscripts, an n-dimensional transpose.'
print,' Category: Array manipulation'
print,' Calling sequence: out_arr=REINDEX(in_arr, sort)
print,' or out_arr=REINDEX(/help)
print,' '
print,' Example: if IN_ARR = intarr(2,3,4,5) then'
print,' out_arr = reindex(in_arr,[2,4,3,1]) results in'
print,' out_arr becomming an array of dimension intarr(3,5,4,2)'
print,' or reindex( f(x,y,z),[2,3,1]) becomes f(y,z,x)'
print,' or reindex( f(x,y,z),[1,2,3]) does nothing
print,' '
print,' Inputs: '
print,' IN_ARR n-dimensional array 1 < n < 8'
print,' SORT vector listing order of subscripts in result'
print,' KEYWORDS"'
print,' /HELP Informs the user about this proceedure'
print,' '
print,' Output: '
print,' OUT_ARR n-dimensional array 1 < n < 8 of same type as IN_ARR '
print,' with subscripts reordered'
print,' '
return,1
endif

; Inquire about input array
sa = size(a)
; Check
nind = n_elements(ind_order)

; Clone a singly dimensioned array
if(nind eq 1) then return,a

; Incompatable arrays
if(sa(0) ne nind) then begin
print,'Number of subscripts does not match array'
help,a,ind_order
return,-1
endif

; Make a destination array
sb = sa([0,ind_order,nind+[1,2]])
b = make_array(size=sb)

; Compute some index arrays
i = lindgen(sa(nind+2))
c = lonarr(sa(nind+2),nind)
e = replicate(1L,nind+1)
d = 1L
for k=0,nind-1 do begin
c(0,k) = (i/d) mod sb(k+1)
d = d*sb(k+1)
e(k+1) = e(k)*sa(k+1)
endfor

; A place for the sorting array
m = lonarr(sa(nind+2))

; Calculate the indicies and fill output array
b(0)=a( c # e( ind_order( indgen(nind) )-1 ) )

; All Done
return,b
end


--------------17601F1B6C24--
Re: array transpose [message #8777 is a reply to message #8773] Tue, 22 April 1997 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Christian Soeller chides me when he writes:

> A guy like you will surely mostly use the online reference and not the
> old printed books. So if you check that it's all there.
>
> I am amazed that many people still seem to prefer the books. When I
> write IDL routines I spent at least half the time in the online help
> looking up proc/func refs ;).

Well, Chrisitan, I can only surmise that you must be younger than
me. When I have the choice between squinting down the end of my
nose and trying to make out those *very* small characters
or looking at the big type in books, I always choose books.

But you shouldn't be so quick to chide. It might happen to you,
too. In fact, if you are like me, sooner than you expected. :-)

Just say, somedays I don't feel like I'm getting any younger...

David

----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
Customizable IDL Programming Courses
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com
Re: array transpose [message #8780 is a reply to message #8773] Tue, 22 April 1997 00:00 Go to previous message
Christian Soeller is currently offline  Christian Soeller
Messages: 46
Registered: August 1996
Member
davidf@dfanning.com (David Fanning) writes:

> What manual are you reading, Christian? Or perhaps more to the point,
> exactly HOW are you reading it!? I don't find this is *my* manual. :-(

A guy like you will surely mostly use the online reference and not the
old printed books. So if you check that it's all there.

I am amazed that many people still seem to prefer the books. When I
write IDL routines I spent at least half the time in the online help
looking up proc/func refs ;).

Christian
Re: array transpose [message #8783 is a reply to message #8773] Mon, 21 April 1997 00:00 Go to previous message
brian.jackel is currently offline  brian.jackel
Messages: 23
Registered: May 1996
Junior Member
In article <5jg445$1mv@danberg.llnl.gov> dan@danberg.llnl.gov (Dan Bergmann) writes:

> Gary Fu <gfu@shark.gsfc.nasa.gov> writes:
> |> Is there a simple way to transpose the array(x,y,z) to array(y,x,z) ?

> Is there something better than

> for i=0,(size(array))(3)-1 do array(*,*,i) = transpose(array(*,*,i))
> array = reform(array,(size(array))(2),(size(array))(1),(size(array)) (3))


In the IDL 4.0 and later (and possibly earlier) documentation
------------------------------------------------------------ -------------------
Calling Sequence Result = TRANSPOSE(Array [, P])

Arguments

Array The array to be transposed.

P A vector specifying how the dimensions of Array will be permuted. The
elements of P correspond to the dimensions of Array; the ith dimension of the
output array is dimension P[i] of the input array. Each element of the vector
P must be unique. Dimensions start at zero and can not be repeated.

If P is not present, the order of the indices of Array is reversed.
------------------------------------------------------------ -------------------

So result= TRANSPOSE( array, [1,0,2] ) should do it.
Re: array transpose [message #8787 is a reply to message #8783] Mon, 21 April 1997 00:00 Go to previous message
Christian Soeller is currently offline  Christian Soeller
Messages: 46
Registered: August 1996
Member
Gary Fu <gfu@shark.gsfc.nasa.gov> writes:

>>
>> RTFM -> transpose function
>>
>> Christian
>
> The TRANSPOSE function will transpose to array(Z,Y,X), not array(Y,X,Z).

And what about transpose(array,[1,0,2]) ?
As I said, it's in the manual; one obviously has to know how to read it ;).

Christian
Re: array transpose [message #8788 is a reply to message #8783] Mon, 21 April 1997 00:00 Go to previous message
William Clodius is currently offline  William Clodius
Messages: 30
Registered: December 1996
Member
David Fanning wrote:
>
> Christian Soeller <csoelle@sghms.ac.uk> writes:
>
>> Gary Fu <gfu@shark.gsfc.nasa.gov> writes:
>>
>>>>
>>>> RTFM -> transpose function
>>>>
>>>> Christian
>>>
>>> The TRANSPOSE function will transpose to array(Z,Y,X), not array(Y,X,Z).
>>
>> And what about transpose(array,[1,0,2]) ?
>> As I said, it's in the manual; one obviously has to know how to read it ;).
>
> What manual are you reading, Christian? Or perhaps more to the point,
> exactly HOW are you reading it!? I don't find this is *my* manual. :-(
>
> In any case, I can't get this to work. Can you perhaps tell us what
> software you are using and give us a simple example.
> <snip>

David:

Assuming you are using IDL and not PV-Wave (PV-Wave might differ on this
point) the Reference Guide or the online documentation accessed by
entering
> ?

both give for the TRANSPOSE function

"The TRANSPOSE function returns the transpose of Array. If an optional
permutation vector is provided, the dimensions of Array are rearranged
as well.

Calling Sequence
Result = TRANSPOSE(Array [, P])

Arguments
...
P
A vector specifying how the dimensions of Array will be permuted.
The elements of P correspond to the dimensions of Array; the ith
dimension of the output array is dimension P(i) of the input array. Each
element of the vector P must be unique. Dimensions start at zero and can
not be repeated.
If P is not present, the order of the indices of Array is
reversed. ...

To see how a multi-dimensional transposition works, first create a
three-dimensional array A:

A = INDGEN(2, 3, 4)

Take the transpose, reversing the order of the indices

B = TRANSPOSE(A)

Now re-order the dimensions of A, so that the second dimension becomes
the first, the third becomes the second and the first becomes the third

C = TRANSPOSE(A, [1, 2, 0])"


--

William B. Clodius Phone: (505)-665-9370
Los Alamos Nat. Lab., NIS-2 FAX: (505)-667-3815
PO Box 1663, MS-C323 Group office: (505)-667-5776
Los Alamos, NM 87545 Email: wclodius@lanl.gov
Re: array transpose [message #8790 is a reply to message #8783] Mon, 21 April 1997 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Christian Soeller <csoelle@sghms.ac.uk> writes:

> Gary Fu <gfu@shark.gsfc.nasa.gov> writes:
>
>>>
>>> RTFM -> transpose function
>>>
>>> Christian
>>
>> The TRANSPOSE function will transpose to array(Z,Y,X), not array(Y,X,Z).
>
> And what about transpose(array,[1,0,2]) ?
> As I said, it's in the manual; one obviously has to know how to read it ;).

What manual are you reading, Christian? Or perhaps more to the point,
exactly HOW are you reading it!? I don't find this is *my* manual. :-(

In any case, I can't get this to work. Can you perhaps tell us what
software you are using and give us a simple example.

Thanks,

David

--
David Fanning, Ph.D.
IDL Training and Consulting
Completely Customized Courses--Guaranteed!
Phone: 970-221-0438 Fax: 970-221-4762
E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com
Re: array transpose [message #8791 is a reply to message #8783] Mon, 21 April 1997 00:00 Go to previous message
dan is currently offline  dan
Messages: 27
Registered: March 1993
Junior Member
In article <33595345.41C6@shark.gsfc.nasa.gov>, Gary Fu <gfu@shark.gsfc.nasa.gov> writes:
|> Hi,
|>
|> Is there a simple way to transpose the array(x,y,z) to array(y,x,z) ?
|>
|> Thanks.
|>
|> Gary

Is there something better than

for i=0,(size(array))(3)-1 do array(*,*,i) = transpose(array(*,*,i))
array = reform(array,(size(array))(2),(size(array))(1),(size(array)) (3))

--
************************************************************ ***
** Dan Bergmann dbergmann@llnl.gov **
** Atmospheric Science Division fax (510) 423-4908 **
** Lawrence Livermore National Lab human (510) 423-6765 **
Re: array transpose [message #8792 is a reply to message #8783] Mon, 21 April 1997 00:00 Go to previous message
Gary Fu is currently offline  Gary Fu
Messages: 9
Registered: April 1997
Junior Member
Christian Soeller wrote:
>
> Gary Fu <gfu@shark.gsfc.nasa.gov> writes:
>
>> Is there a simple way to transpose the array(x,y,z) to array(y,x,z) ?
>
> RTFM -> transpose function
>
> Christian

The TRANSPOSE function will transpose to array(Z,Y,X), not array(Y,X,Z).

Gary
Re: array transpose [message #8797 is a reply to message #8783] Sun, 20 April 1997 00:00 Go to previous message
Christian Soeller is currently offline  Christian Soeller
Messages: 46
Registered: August 1996
Member
Gary Fu <gfu@shark.gsfc.nasa.gov> writes:

> Is there a simple way to transpose the array(x,y,z) to array(y,x,z) ?

RTFM -> transpose function

Christian
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Object Oriented Programming Book Recommendation
Next Topic: Interactive image viewer in IDL?

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

Current Time: Wed Oct 08 14:01:23 PDT 2025

Total time taken to generate the page: 0.00816 seconds