ee.Image.arrayRepeat

Repite cada píxel del array a lo largo del eje determinado. Cada píxel de salida tendrá la forma del píxel de entrada, excepto la longitud a lo largo del eje repetido, que se multiplicará por la cantidad de copias.

UsoMuestra
Image.arrayRepeat(axis, copies)Imagen
ArgumentoTipoDetalles
esta: inputImagenImagen de los píxeles del array que se repetirán.
axisNúmero enteroEs el eje a lo largo del cual se repite el array de cada píxel.
copiesImagenCantidad de copias de cada píxel.

Ejemplos

Editor de código (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]

// Repeat a 1D array along the 0-axis 3 times.
var repeat1DAx0 = arrayImg1D.arrayRepeat(0, 3);
print('1D array repeated 3 times on 0-axis', sampArrImg(repeat1DAx0));
// [0, 1, 2, 0, 1, 2, 0, 1, 2]

// Repeat a 1D array along the 1-axis 3 times (expands the dimensions).
var repeat1DAx1 = arrayImg1D.arrayRepeat(1, 3);
print('1D array repeated 3 times on 1-axis', sampArrImg(repeat1DAx1));
// [[0, 0, 0],
//  [1, 1, 1],
//  [2, 2, 2]]

// Repeat a 2D array along the 0-axis 2 times.
var repeat2DAx0 = repeat1DAx1.arrayRepeat(0, 2);
print('2D array repeated 2 times on 0-axis', sampArrImg(repeat2DAx0));
// [[0, 0, 0],
//  [1, 1, 1],
//  [2, 2, 2],
//  [0, 0, 0],
//  [1, 1, 1],
//  [2, 2, 2]]

// Repeat a 2D array along the 1-axis 2 times.
var repeat2DAx1 = repeat1DAx1.arrayRepeat(1, 2);
print('2D array repeated 2 times on 1-axis', sampArrImg(repeat2DAx1));
// [[0, 0, 0, 0, 0, 0],
//  [1, 1, 1, 1, 1, 1],
//  [2, 2, 2, 2, 2, 2]]

Configuración de Python

Consulta la página Entorno de Python para obtener información sobre la API de Python y el uso de geemap para el desarrollo interactivo.

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()
print('1D array image (pixel):', samp_arr_img(array_img_1d).getInfo())
# [0, 1, 2]

# Repeat a 1D array along the 0-axis 3 times.
repeat_1d_ax0 = array_img_1d.arrayRepeat(0, 3)
print(
    '1D array repeated 3 times on 0-axis:',
    samp_arr_img(repeat_1d_ax0).getInfo()
)
# [0, 1, 2, 0, 1, 2, 0, 1, 2]

# Repeat a 1D array along the 1-axis 3 times (expands the dimensions).
repeat_1d_ax1 = array_img_1d.arrayRepeat(1, 3)
print(
    '1D array repeated 3 times on 1-axis:',
    samp_arr_img(repeat_1d_ax1).getInfo()
)
# [[0, 0, 0],
#  [1, 1, 1],
#  [2, 2, 2]]

# Repeat a 2D array along the 0-axis 2 times.
repeat_2d_ax0 = repeat_1d_ax1.arrayRepeat(0, 2)
print(
    '2D array repeated 2 times on 0-axis:',
    samp_arr_img(repeat_2d_ax0).getInfo()
)
# [[0, 0, 0],
#  [1, 1, 1],
#  [2, 2, 2],
#  [0, 0, 0],
#  [1, 1, 1],
#  [2, 2, 2]]

# Repeat a 2D array along the 1-axis 2 times.
repeat_2d_ax1 = repeat_1d_ax1.arrayRepeat(1, 2)
print(
    '2D array repeated 2 times on 1-axis:',
    samp_arr_img(repeat_2d_ax1).getInfo()
)
# [[0, 0, 0, 0, 0, 0],
#  [1, 1, 1, 1, 1, 1],
#  [2, 2, 2, 2, 2, 2]]