ee.Array.firstNonZero

Chọn giá trị đầu tiên nếu giá trị đó khác 0 và chọn giá trị thứ hai nếu giá trị đó bằng 0.

Cách sử dụngGiá trị trả về
Array.firstNonZero(right)Mảng
Đối sốLoạiThông tin chi tiết
this: leftMảngGiá trị bên trái.
rightMảngGiá trị bên phải.

Ví dụ

Trình soạn thảo mã (JavaScript)

var empty = ee.Array([], ee.PixelType.int8());
print(empty.firstNonZero(empty));  // []

print(ee.Array([0]).firstNonZero(0));  // [0]
print(ee.Array([0]).firstNonZero([0]));  // [0]
print(ee.Array([0]).firstNonZero([1]));  // [1]
print(ee.Array([2]).firstNonZero([3]));  // [2]
print(ee.Array([1]).firstNonZero([0]));  // [1]

print(ee.Array([-1, 0, 1]).firstNonZero([2, -1, 2]));  // [-1,-1,1]

// [[1,2],[3,4]]
print(ee.Array([[1, 2], [0, 0]]).firstNonZero([[0, 0], [3, 4]]));

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về API Python và cách sử dụng geemap cho quá trình phát triển tương tác.

import ee
import geemap.core as geemap

Colab (Python)

empty = ee.Array([], ee.PixelType.int8())
display(empty.firstNonZero(empty))  # []

display(ee.Array([0]).firstNonZero(0))  # [0]
display(ee.Array([0]).firstNonZero([0]))  # [0]
display(ee.Array([0]).firstNonZero([1]))  # [1]
display(ee.Array([2]).firstNonZero([3]))  # [2]
display(ee.Array([1]).firstNonZero([0]))  # [1]

display(ee.Array([-1, 0, 1]).firstNonZero([2, -1, 2]))  # [-1, -1, 1]

# [[1, 2], [3, 4]]
display(ee.Array([[1, 2], [0, 0]]).firstNonZero([[0, 0], [3, 4]]))