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

Home » Public Forums » archive » Re: 2D to 3D Array
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: 2D to 3D Array [message #48315] Fri, 07 April 2006 13:57
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
rafaloos@gmail.com writes:

> Thanks ...
> It perfectly worked ... (:

It pays to read the Dimensional Juggling Tutorial once
in awhile. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: 2D to 3D Array [message #48317 is a reply to message #48315] Fri, 07 April 2006 13:41 Go to previous message
rafaloos is currently offline  rafaloos
Messages: 15
Registered: January 2006
Junior Member
Thanks ...
It perfectly worked ... (:
Re: 2D to 3D Array [message #48320 is a reply to message #48317] Fri, 07 April 2006 13:21 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
rafaloos@gmail.com wrote:
> I have a Band Interleaved Image (BIL):
> samples = 300
> lines = 316
> bands = 481
>
> I can read this image as a 2D array of (144300, 316) Where 144300 will
> be the product of samples by bands.
> I would like to reformat the image so that I can put the data into an
> array such as (300, 316, 481).
>
> For example: I have this array (6,2)
>
> array[*,0] = [1, 2, 1, 2, 1, 2]
> array[*,1] = [3, 4, 3, 4, 3, 4]
>
> What I want is a result as:
>
> array[*,*,0] = 1, 2
> 3, 4
>
> array[*,*,1] = 1, 2
> 3 ,4
>
> array[*,*,2] = 1, 2
> 3, 4
>
> so that my array will be (2,2,3)

REFORM your [144300,316] array to [300,481,316], and then use TRANSPOSE to swap the last
two indices. E.g.

IDL> array=lonarr(8,2)
IDL> array[*,0] = [1, 2, 1, 2, 1, 2, 1, 2]
IDL> array[*,1] = [3, 4, 3, 4, 3, 4, 3, 4]
IDL> help, array
ARRAY LONG = Array[8, 2]
IDL> a=reform(array,2,4,2)
IDL> help, a
A LONG = Array[2, 4, 2]
IDL> print, a[*,*,0]
1 2
1 2
1 2
1 2
IDL> print, a[*,*,1]
3 4
3 4
3 4
3 4
IDL> b=transpose(a,[0,2,1])
IDL> help, b
B LONG = Array[2, 2, 4]
IDL> print, b[*,*,0]
1 2
3 4
IDL> print, b[*,*,1]
1 2
3 4
IDL> print, b[*,*,2]
1 2
3 4
IDL> print, b[*,*,3]
1 2
3 4



paulv


--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
Re: 2D to 3D Array [message #48321 is a reply to message #48320] Fri, 07 April 2006 13:19 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
rafaloos@gmail.com writes:

> I have a Band Interleaved Image (BIL):
> samples = 300
> lines = 316
> bands = 481
>
> I can read this image as a 2D array of (144300, 316) Where 144300 will
> be the product of samples by bands.
> I would like to reformat the image so that I can put the data into an
> array such as (300, 316, 481).
>
> For example: I have this array (6,2)
>
> array[*,0] = [1, 2, 1, 2, 1, 2]
> array[*,1] = [3, 4, 3, 4, 3, 4]
>
> What I want is a result as:
>
> array[*,*,0] = 1, 2
> 3, 4
>
> array[*,*,1] = 1, 2
> 3 ,4
>
> array[*,*,2] = 1, 2
> 3, 4
>
> so that my array will be (2,2,3)

First reform your array into a [2,3,2] array:

array = Reform(array, 2, 3, 2)

Then, transpose the dimensions the way you want them:

array = Transpose(array, [0,2,1])

IDL> print, array[*,*,2]
1 2
3 4
IDL> print, array[*,*,1]
1 2
3 4
IDL> print, array[*,*,0]
1 2
3 4

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: 2D to 3D Array
Next Topic: Re: Day/Night Terminator on Map Projection

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

Current Time: Wed Oct 08 15:36:29 PDT 2025

Total time taken to generate the page: 0.00654 seconds