Thông báo : Tất cả dự án phi thương mại đã đăng ký sử dụng Earth Engine trước
ngày 15 tháng 4 năm 2025 phải
xác minh điều kiện sử dụng phi thương mại để duy trì quyền truy cập. Nếu bạn chưa xác minh trước ngày 26 tháng 9 năm 2025, quyền truy cập của bạn có thể bị tạm ngưng.
Gửi ý kiến phản hồi
ee.List.iterate
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Lặp lại một thuật toán trên danh sách. Thuật toán này dự kiến sẽ lấy 2 đối tượng, mục danh sách hiện tại và kết quả từ lần lặp lại trước hoặc giá trị của first cho lần lặp lại đầu tiên.
Cách sử dụng Giá trị trả về List. iterate (function, first)
Đối tượng
Đối số Loại Thông tin chi tiết this: list
Danh sách function
Thuật toán first
Đối tượng
Ví dụ
Trình soạn thảo mã (JavaScript)
// This example uses the ee.List.iterate function to generate a series of
// sequentially halved values.
// Declare a list that will hold the series of sequentially halved values,
// initialize it with the starting quantity.
var quantityList = [ 1000 ];
// Define the number of iterations as a list sequence.
var nSteps = ee . List . sequence ( 1 , 10 );
// Declare a function that takes the current element of the iteration list and
// the returned result of the previous iteration as inputs. In this case, the
// the function is returning an accumulating list of quantities that are reduced
// by half at each iteration.
var halfOfPrevious = function ( currentElement , previousResult ) {
var previousQuantity = ee . Number ( ee . List ( previousResult ). get ( - 1 ));
var currentQuantity = previousQuantity . divide ( 2 );
return ee . List ( previousResult ). add ( currentQuantity );
};
// Apply the function to the nSteps list, each element is an iteration.
quantityList = ee . List ( nSteps . iterate ( halfOfPrevious , quantityList ));
// Display the results. Note that step 0 is included for the initial value.
print ( 'Steps in the iteration of halved quantities' , nSteps );
print ( 'Series of sequentially halved quantities' , quantityList );
print ( ui . Chart . array . values ({
array : quantityList ,
axis : 0 ,
xLabels : ee . List ([ 0 ]). cat ( nSteps )
}));
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)
import matplotlib.pyplot as plt
# This example uses the ee.List.iterate function to generate a series of
# sequentially halved values.
# Declare a list that will hold the series of sequentially halved values,
# initialize it with the starting quantity.
quantity_list = [ 1000 ]
# Define the number of iterations as a list sequence.
n_steps = ee . List . sequence ( 1 , 10 )
# Declare a function that takes the current element of the iteration list and
# the returned result of the previous iteration as inputs. In this case, the
# the function is returning an accumulating list of quantities that are reduced
# by half at each iteration.
def half_of_previous ( current_element , previous_result ):
previous_quantity = ee . Number ( ee . List ( previous_result ) . get ( - 1 ))
current_quantity = previous_quantity . divide ( 2 )
return ee . List ( previous_result ) . add ( current_quantity )
# Apply the function to the n_steps list, each element is an iteration.
quantity_list = ee . List ( n_steps . iterate ( half_of_previous , quantity_list ))
# Display the results.
display ( 'Steps in the iteration of halved quantities' , n_steps )
display ( 'Series of sequentially halved quantities' , quantity_list )
quantity_list_client = quantity_list . getInfo ()
plt . scatter ( range ( len ( quantity_list_client )), quantity_list_client )
plt . show ()
Gửi ý kiến phản hồi
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0 . Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers . Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
Bạn muốn chia sẻ thêm với chúng tôi?
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[],[]]