Cách sử dụng | Giá trị trả về |
---|---|
Array.slice(axis, start, end, step) | Mảng |
Đối số | Loại | Thông tin chi tiết |
---|---|---|
this: array | Mảng | Mảng cần phân đoạn. |
axis | Số nguyên, mặc định: 0 | Trục cần phân đoạn. |
start | Số nguyên, mặc định: 0 | Toạ độ của lát đầu tiên (bao gồm) dọc theo "trục". Các số âm được dùng để định vị điểm bắt đầu của việc phân đoạn tương ứng với điểm cuối của mảng, trong đó -1 bắt đầu ở vị trí cuối cùng trên trục, -2 bắt đầu ở vị trí áp chót, v.v. |
end | Số nguyên, mặc định: null | Toạ độ (loại trừ) tại đó ngừng lấy các lát. Theo mặc định, đây sẽ là chiều dài của trục đã cho. Số âm được dùng để định vị điểm cuối của việc phân đoạn tương ứng với điểm cuối của mảng, trong đó -1 sẽ loại trừ vị trí cuối cùng, -2 sẽ loại trừ 2 vị trí cuối cùng, v.v. |
step | Số nguyên, mặc định: 1 | Khoảng cách giữa các lát cắt dọc theo "trục"; một lát cắt sẽ được lấy tại mỗi bội số nguyên của "bước" từ "bắt đầu" (bao gồm) đến "kết thúc" (không bao gồm). Phải là số dương. |
Ví dụ
Trình soạn thảo mã (JavaScript)
var array1x6 = ee.Array([1, 2, 3, 4, 5, 6]); print(array1x6.slice()); // [1,2,3,4,5,6] print(array1x6.slice(0)); // [1,2,3,4,5,6] print(array1x6.slice(0, 0, 6, 1)); // [1,2,3,4,5,6] print(array1x6.slice(0, 0, 10, 1)); // [1,2,3,4,5,6] print(array1x6.slice(0, 2)); // [3,4,5,6] print(array1x6.slice(0, 5)); // [6] print(array1x6.slice(0, 6)); // [] print(array1x6.slice(0, 0, 2)); // [1,2] print(array1x6.slice(0, 0, 0)); // [] // Negative start and end. print(array1x6.slice(0, 0, -3)); // [1,2,3] print(array1x6.slice(0, -2, 6)); // [5,6] print(array1x6.slice(0, 0, 6, 2)); // [1,3,5] print(array1x6.slice(0, 0, 6, 3)); // [1,4] print(array1x6.slice(0, 0, 6, 4)); // [1,5] print(array1x6.slice(0, 0, 6, 6)); // [1] print(array1x6.slice(0, 2, 6, 2)); // [3,5] var array3x2 = ee.Array([[1, 2], [3, 4], [5, 6]]); print(array3x2.slice()); // [[1,2],[3,4],[5,6]] print(array3x2.slice(0)); // [[1,2],[3,4],[5,6]] print(array3x2.slice(0, 0)); // [[1,2],[3,4],[5,6]] print(array3x2.slice(0, 0, 1)); // [[1,2]] print(array3x2.slice(0, 0, 2)); // [[1,2],[3,4]] print(array3x2.slice(0, 0, 3, 1)); // [[1,2],[3,4],[5,6]] print(array3x2.slice(0, 0, 3, 2)); // [[1,2],[5,6]] print(array3x2.slice(0, 1, 3, 2)); // [[3,4]] print(array3x2.slice(0, 0, 3, 3)); // [[1,2]] print(array3x2.slice(1)); // [[1,2],[3,4],[5,6]] print(array3x2.slice(1, 1)); // [[2],[4],[6]] print(array3x2.slice(1, 0, 1)); // [[1],[3],[5]] var empty = ee.Array([], ee.PixelType.int8()); print(empty.slice()); // [] print(empty.slice(0)); // [] print(empty.slice(0, 0, 0, 1)); // []
import ee import geemap.core as geemap
Colab (Python)
array1x6 = ee.Array([1, 2, 3, 4, 5, 6]) display(array1x6.slice()) # [1, 2, 3, 4, 5, 6] display(array1x6.slice(0)) # [1, 2, 3, 4, 5, 6] display(array1x6.slice(0, 0, 6, 1)) # [1, 2, 3, 4, 5, 6] display(array1x6.slice(0, 0, 10, 1)) # [1, 2, 3, 4, 5, 6] display(array1x6.slice(0, 2)) # [3, 4, 5, 6] display(array1x6.slice(0, 5)) # [6] display(array1x6.slice(0, 6)) # [] display(array1x6.slice(0, 0, 2)) # [1, 2] display(array1x6.slice(0, 0, 0)) # [] # Negative start and end. display(array1x6.slice(0, 0, -3)) # [1, 2, 3] display(array1x6.slice(0, -2, 6)) # [5, 6] display(array1x6.slice(0, 0, 6, 2)) # [1, 3, 5] display(array1x6.slice(0, 0, 6, 3)) # [1, 4] display(array1x6.slice(0, 0, 6, 4)) # [1, 5] display(array1x6.slice(0, 0, 6, 6)) # [1] display(array1x6.slice(0, 2, 6, 2)) # [3, 5] array3x2 = ee.Array([[1, 2], [3, 4], [5, 6]]) display(array3x2.slice()) # [[1, 2], [3, 4], [5, 6]] display(array3x2.slice(0)) # [[1, 2], [3, 4], [5, 6]] display(array3x2.slice(0, 0)) # [[1, 2],[3, 4],[5, 6]] display(array3x2.slice(0, 0, 1)) # [[1, 2]] display(array3x2.slice(0, 0, 2)) # [[1, 2], [3, 4]] display(array3x2.slice(0, 0, 3, 1)) # [[1, 2], [3, 4], [5, 6]] display(array3x2.slice(0, 0, 3, 2)) # [[1, 2], [5, 6]] display(array3x2.slice(0, 1, 3, 2)) # [[3, 4]] display(array3x2.slice(0, 0, 3, 3)) # [[1, 2]] display(array3x2.slice(1)) # [[1, 2], [3, 4], [5, 6]] display(array3x2.slice(1, 1)) # [[2], [4], [6]] display(array3x2.slice(1, 0, 1)) # [[1], [3], [5]] empty = ee.Array([], ee.PixelType.int8()) display(empty.slice()) # [] display(empty.slice(0)) # [] display(empty.slice(0, 0, 0, 1)) # []