ee.Image.arrayTranspose

Transposes two dimensions of each array pixel.
Usage Returns
Image. arrayTranspose ( axis1 , axis2 ) Image
Argument Type Details
this: input
Image Input image.
axis1
Integer, default: 0 First axis to swap.
axis2
Integer, default: 1 Second axis to swap.

Examples

Code Editor (JavaScript)

 // A function to print arrays for a selected pixel in the following examples. 
 function 
  
 sampArrImg 
 ( 
 arrImg 
 ) 
  
 { 
  
 var 
  
 point 
  
 = 
  
 ee 
 . 
 Geometry 
 . 
 Point 
 ([ 
 - 
 121 
 , 
  
 42 
 ]); 
  
 return 
  
 arrImg 
 . 
 sample 
 ( 
 point 
 , 
  
 500 
 ). 
 first 
 (). 
 get 
 ( 
 'array' 
 ); 
 } 
 // Create a 2D array image. 
 var 
  
 arrayImg2D 
  
 = 
  
 ee 
 . 
 Image 
 ([ 
 0 
 , 
  
 1 
 , 
  
 2 
 , 
  
 3 
 , 
  
 4 
 , 
  
 5 
 ]). 
 toArray 
 (). 
 arrayReshape 
 ( 
  
 ee 
 . 
 Image 
 ([ 
 2 
 , 
  
 3 
 ]). 
 toArray 
 (), 
  
 2 
 ); 
 print 
 ( 
 '2D 2x3 array image (pixel)' 
 , 
  
 sampArrImg 
 ( 
 arrayImg2D 
 )); 
 // [[0, 1, 2], 
 //  [3, 4, 5]] 
 // Swap 0-axis and 1-axis. Input is a 2x3 array, output will be 3x2. 
 var 
  
 transposed 
  
 = 
  
 arrayImg2D 
 . 
 arrayTranspose 
 (); 
 print 
 ( 
 'Transposed (3x2) array image (pixel)' 
 , 
  
 sampArrImg 
 ( 
 transposed 
 )); 
 // [[0, 3], 
 //  [1, 4], 
 //  [2, 5]] 

Python setup

See the Python Environment page for information on the Python API and using geemap for interactive development.

 import 
  
 ee 
 import 
  
 geemap.core 
  
 as 
  
 geemap 

Colab (Python)

 # A function to print arrays for a selected pixel in the following examples. 
 def 
  
 samp_arr_img 
 ( 
 arr_img 
 ): 
 point 
 = 
 ee 
 . 
 Geometry 
 . 
 Point 
 ([ 
 - 
 121 
 , 
 42 
 ]) 
 return 
 arr_img 
 . 
 sample 
 ( 
 point 
 , 
 500 
 ) 
 . 
 first 
 () 
 . 
 get 
 ( 
 'array' 
 ) 
 # Create a 2D array image. 
 array_img_2d 
 = 
 ee 
 . 
 Image 
 ([ 
 0 
 , 
 1 
 , 
 2 
 , 
 3 
 , 
 4 
 , 
 5 
 ]) 
 . 
 toArray 
 () 
 . 
 arrayReshape 
 ( 
 ee 
 . 
 Image 
 ([ 
 2 
 , 
 3 
 ]) 
 . 
 toArray 
 (), 
 2 
 ) 
 print 
 ( 
 '2D 2x3 array image (pixel):' 
 , 
 samp_arr_img 
 ( 
 array_img_2d 
 ) 
 . 
 getInfo 
 ()) 
 # [[0, 1, 2], 
 #  [3, 4, 5]] 
 # Swap 0-axis and 1-axis. Input is a 2x3 array, output will be 3x2. 
 transposed 
 = 
 array_img_2d 
 . 
 arrayTranspose 
 () 
 print 
 ( 
 'Transposed (3x2) array image (pixel):' 
 , 
 samp_arr_img 
 ( 
 transposed 
 ) 
 . 
 getInfo 
 ()) 
 # [[0, 3], 
 #  [1, 4], 
 #  [2, 5]] 
Create a Mobile Website
View Site in Mobile | Classic
Share by: