ee.Image.arrayRepeat

沿指定軸重複每個陣列像素。每個輸出像素的形狀都會與輸入像素相同,但沿著重複軸的長度會乘以副本數。

用量傳回
Image.arrayRepeat(axis, copies)圖片
引數類型詳細資料
這個:input圖片要重複的陣列像素圖片。
axis整數要沿著哪個軸重複每個像素的陣列。
copies圖片每個像素的副本數量。

範例

程式碼編輯器 (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]]

Python 設定

請參閱 Python 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

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