ee.Image.arrayRepeat

Repete cada pixel da matriz ao longo do eixo especificado. Cada pixel de saída terá o formato do pixel de entrada, exceto o comprimento ao longo do eixo repetido, que será multiplicado pelo número de cópias.

UsoRetorna
Image.arrayRepeat(axis, copies)Imagem
ArgumentoTipoDetalhes
isso: inputImagemImagem dos pixels da matriz a serem repetidos.
axisNúmero inteiroEixo ao longo do qual repetir a matriz de cada pixel.
copiesImagemNúmero de cópias de cada pixel.

Exemplos

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]]

Configuração do Python

Consulte a página Ambiente Python para informações sobre a API Python e como usar geemap para desenvolvimento interativo.

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]]