|
|
Re: 2D to 3D Array [message #48320 is a reply to message #48317] |
Fri, 07 April 2006 13:21  |
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  |
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/
|
|
|