AI-generated Key Takeaways
-
Image.arrayPadpads the array values in each pixel to a fixed length by appending a specified value to each array. -
All bands of the input image must be array-valued and have the same dimensions for
Image.arrayPadto work. -
The
lengthsargument is a list of desired lengths for each axis in the output arrays. -
The
padargument specifies the value to use for padding, defaulting to 0.
| Usage | Returns |
|---|---|
Image.
arrayPad
(lengths, pad
)
|
Image |
| Argument | Type | Details |
|---|---|---|
|
this:
image
|
Image | Array image to pad. |
lengths
|
List | A list of desired lengths for each axis in the output arrays. Arrays are already as large or larger than the given length will be unchanged along that axis. |
pad
|
Number, default: 0 | The value to pad with. |
Examples
Code Editor (JavaScript)
// A function to print the array 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 1D array image. var arrayImg1D = ee . Image ([ 0 , 1 , 2 ]). toArray (); print ( '1D array image (pixel)' , sampArrImg ( arrayImg1D )); // [0, 1, 2] // Pad 1D array to length of 5 with value 9. var arrayImg1Dpad = arrayImg1D . arrayPad ([ 5 ], 9 ); print ( '1D array image padded' , sampArrImg ( arrayImg1Dpad )); // [0, 1, 2, 9, 9] // 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]] // Pad 2D array to 0-axis length 3 and 1-axis length 5 with value 9. var arrayImg2Dpad = arrayImg2D . arrayPad ([ 3 , 5 ], 9 ); print ( '2D array image padded' , sampArrImg ( arrayImg2Dpad )); // [[0, 1, 2, 9, 9], // [3, 4, 5, 9, 9], // [9, 9, 9, 9, 9]]
import ee import geemap.core as geemap
Colab (Python)
# A function to print the array 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 1D array image. array_img_1d = ee . Image ([ 0 , 1 , 2 ]) . toArray () display ( '1D array image (pixel):' , samp_arr_img ( array_img_1d )) # [0, 1, 2] # Pad 1D array to length of 5 with value 9. array_img_1d_pad = array_img_1d . arrayPad ([ 5 ], 9 ) display ( '1D array image padded:' , samp_arr_img ( array_img_1d_pad )) # [0, 1, 2, 9, 9] # Create a 2D array image. array_img_2d = ee . Image ([ 0 , 1 , 2 , 3 , 4 , 5 ]) . toArray () . arrayReshape ( ee . Image ([ 2 , 3 ]) . toArray (), 2 ) display ( '2D 2x3 array image (pixel):' , samp_arr_img ( array_img_2d )) # [[0, 1, 2], # [3, 4, 5]] # Pad 2D array to 0-axis length 3 and 1-axis length 5 with value 9. array_img_2d_pad = array_img_2d . arrayPad ([ 3 , 5 ], 9 ) display ( '2D array image padded:' , samp_arr_img ( array_img_2d_pad )) # [[0, 1, 2, 9, 9], # [3, 4, 5, 9, 9], # [9, 9, 9, 9, 9]]

