Anúncio: todos os projetos não comerciais registrados para usar o Earth Engine antes de
15 de abril de 2025 precisam
verificar a qualificação não comercial para manter o acesso ao Earth Engine.
ee.List.iterate
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Iterar um algoritmo em uma lista. O algoritmo deve receber dois objetos: o item da lista atual e o resultado da iteração anterior ou o valor de "first" para a primeira iteração.
Uso | Retorna |
---|
List.iterate(function, first) | Objeto |
Argumento | Tipo | Detalhes |
---|
isso: list | Lista | |
function | Algoritmo | |
first | Objeto | |
Exemplos
Editor de código (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)
}));
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)
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()
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
Última atualização 2025-07-26 UTC.
[null,null,["Última atualização 2025-07-26 UTC."],[[["\u003cp\u003e\u003ccode\u003eList.iterate\u003c/code\u003e repeatedly applies a given algorithm to each element of a list, using the previous iteration's result.\u003c/p\u003e\n"],["\u003cp\u003eThe provided algorithm takes two arguments: the current list element and the previous result (or an initial value for the first iteration).\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eList.iterate\u003c/code\u003e returns the final result after processing all elements.\u003c/p\u003e\n"],["\u003cp\u003eThis function is useful for accumulating values, applying recursive operations, or building complex sequences based on list elements.\u003c/p\u003e\n"]]],[],null,["# ee.List.iterate\n\nIterate an algorithm over a list. The algorithm is expected to take two objects, the current list item, and the result from the previous iteration or the value of first for the first iteration.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|---------------------------------|---------|\n| List.iterate`(function, first)` | Object |\n\n| Argument | Type | Details |\n|--------------|-----------|---------|\n| this: `list` | List | |\n| `function` | Algorithm | |\n| `first` | Object | |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// This example uses the ee.List.iterate function to generate a series of\n// sequentially halved values.\n\n// Declare a list that will hold the series of sequentially halved values,\n// initialize it with the starting quantity.\nvar quantityList = [1000];\n\n// Define the number of iterations as a list sequence.\nvar nSteps = ee.List.sequence(1, 10);\n\n// Declare a function that takes the current element of the iteration list and\n// the returned result of the previous iteration as inputs. In this case, the\n// the function is returning an accumulating list of quantities that are reduced\n// by half at each iteration.\nvar halfOfPrevious = function(currentElement, previousResult) {\n var previousQuantity = ee.Number(ee.List(previousResult).get(-1));\n var currentQuantity = previousQuantity.divide(2);\n return ee.List(previousResult).add(currentQuantity);\n};\n\n// Apply the function to the nSteps list, each element is an iteration.\nquantityList = ee.List(nSteps.iterate(halfOfPrevious, quantityList));\n\n// Display the results. Note that step 0 is included for the initial value.\nprint('Steps in the iteration of halved quantities', nSteps);\nprint('Series of sequentially halved quantities', quantityList);\nprint(ui.Chart.array.values({\n array: quantityList,\n axis: 0,\n xLabels: ee.List([0]).cat(nSteps)\n}));\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\nimport matplotlib.pyplot as plt\n\n# This example uses the ee.List.iterate function to generate a series of\n# sequentially halved values.\n\n# Declare a list that will hold the series of sequentially halved values,\n# initialize it with the starting quantity.\nquantity_list = [1000]\n\n# Define the number of iterations as a list sequence.\nn_steps = ee.List.sequence(1, 10)\n\n\n# Declare a function that takes the current element of the iteration list and\n# the returned result of the previous iteration as inputs. In this case, the\n# the function is returning an accumulating list of quantities that are reduced\n# by half at each iteration.\ndef half_of_previous(current_element, previous_result):\n previous_quantity = ee.Number(ee.List(previous_result).get(-1))\n current_quantity = previous_quantity.divide(2)\n return ee.List(previous_result).add(current_quantity)\n\n\n# Apply the function to the n_steps list, each element is an iteration.\nquantity_list = ee.List(n_steps.iterate(half_of_previous, quantity_list))\n\n# Display the results.\ndisplay('Steps in the iteration of halved quantities', n_steps)\ndisplay('Series of sequentially halved quantities', quantity_list)\nquantity_list_client = quantity_list.getInfo()\nplt.scatter(range(len(quantity_list_client)), quantity_list_client)\nplt.show()\n```"]]