ee.Array.mod
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
מחשבת את השארית של הערך הראשון חלקי הערך השני, על בסיס כל רכיב בנפרד.
שימוש | החזרות |
---|
Array.mod(right) | מערך |
ארגומנט | סוג | פרטים |
---|
זה: left | מערך | הערך בצד ימין. |
right | מערך | הערך בצד שמאל. |
דוגמאות
עורך הקוד (JavaScript)
var empty = ee.Array([], ee.PixelType.int8());
print(empty.mod(empty)); // []
print(ee.Array([0, 0]).mod(ee.Array([-1, 2]))); // [0,0]
print(ee.Array([0, 1, 2, 3, 4]).mod(ee.Array([1, 1, 1, 1, 1]))); // [0,0,0,0,0]
print(ee.Array([0, 1, 2, 3, 4]).mod(ee.Array([2, 2, 2, 2, 2]))); // [0,1,0,1,0]
print(ee.Array([0, 1, 7, 8, 9]).mod(ee.Array([8, 8, 8, 8, 8]))); // [0,1,7,0,1]
print(ee.Array([-1, -7, -8, -9]).mod(ee.Array([8, 8, 8, 8]))); // [-1,-7,0,-1]
print(ee.Array([8, 8, 8, 8]).mod(ee.Array([-1, -7, -8, -9]))); // [0,1,0,8]
print(ee.Array([2.5]).mod(ee.Array([1.2]))); // [0.10000000000000009]
// Generate a square wave graph using mod.
var start = -10;
var end = 10;
var numElements = 1000;
var stepSize = 2;
var points = ee.Array(ee.List.sequence(start, end, null, numElements));
var modValues = ee.Array([stepSize]).repeat(0, numElements);
var values = points.mod(modValues).floor();
// Plot mod().floor() defined above.
// Generate a square wave that is different for negative and positive values.
var chart = ui.Chart.array.values(values, 0, points)
.setOptions({
viewWindow: {min: start, max: end},
hAxis: {
title: 'x',
viewWindowMode: 'maximized'
},
vAxis: {
title: 'mod().floor()',
ticks: [{v: -3}, {v: -2}, {v: -1}, {v: 0}, {v: 1}, {v: 2}]
},
lineWidth: 1,
pointSize: 0,
});
print(chart);
הגדרת Python
מידע על Python API ועל שימוש ב-geemap
לפיתוח אינטראקטיבי מופיע בדף
Python Environment.
import ee
import geemap.core as geemap
Colab (Python)
import altair as alt
import pandas as pd
empty = ee.Array([], ee.PixelType.int8())
display(empty.mod(empty)) # []
display(ee.Array([0, 0]).mod(ee.Array([-1, 2]))) # [0,0]
# [0,0,0,0,0]
display(ee.Array([0, 1, 2, 3, 4]).mod(ee.Array([1, 1, 1, 1, 1])))
# [0,1,0,1,0]
display(ee.Array([0, 1, 2, 3, 4]).mod(ee.Array([2, 2, 2, 2, 2])))
# [0,1,7,0,1]
display(ee.Array([0, 1, 7, 8, 9]).mod(ee.Array([8, 8, 8, 8, 8])))
# [-1,-7,0,-1]
display(ee.Array([-1, -7, -8, -9]).mod(ee.Array([8, 8, 8, 8])))
# [0,1,0,8]
display(ee.Array([8, 8, 8, 8]).mod(ee.Array([-1, -7, -8, -9])))
display(ee.Array([2.5]).mod(ee.Array([1.2]))) # [0.10000000000000009]
# Generate a square wave graph using mod.
start = -10
end = 10
num_elements = 1000
step_size = 2
points = ee.Array(ee.List.sequence(start, end, None, num_elements))
mod_values = ee.Array([step_size]).repeat(0, num_elements)
values = points.mod(mod_values).floor()
df = pd.DataFrame({'x': points.getInfo(), 'mod()': values.getInfo()})
# Plot mod().floor() defined above.
# Generate a square wave that is different for negative and positive values.
alt.Chart(df).mark_line().encode(
x=alt.X('x'),
y=alt.Y('mod()', axis=alt.Axis(values=[-3, -2, -1, 0, 1, 2]))
)
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-26 (שעון UTC).
[null,null,["עדכון אחרון: 2025-07-26 (שעון UTC)."],[[["\u003cp\u003e\u003ccode\u003eArray.mod()\u003c/code\u003e calculates the element-wise remainder of the division between two input arrays.\u003c/p\u003e\n"],["\u003cp\u003eThe function takes two arrays, \u003ccode\u003eleft\u003c/code\u003e and \u003ccode\u003eright\u003c/code\u003e, as input, representing the dividend and divisor respectively.\u003c/p\u003e\n"],["\u003cp\u003eIt returns a new array containing the remainders of each element-wise division.\u003c/p\u003e\n"],["\u003cp\u003eThe function supports both integer and floating-point values.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eArray.mod()\u003c/code\u003e can be used to generate periodic patterns like square waves.\u003c/p\u003e\n"]]],["The `Array.mod(right)` function calculates the remainder of element-wise division between two arrays. It takes a `left` array and a `right` array as input and returns a new array containing the remainders. For example, `[0, 1, 2, 3, 4].mod([2, 2, 2, 2, 2])` results in `[0, 1, 0, 1, 0]`. This operation can be used to generate wave patterns, such as a square wave by using the `mod().floor()` method.\n"],null,["# ee.Array.mod\n\nOn an element-wise basis, calculates the remainder of the first value divided by the second.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|--------------------|---------|\n| Array.mod`(right)` | Array |\n\n| Argument | Type | Details |\n|--------------|-------|-----------------------|\n| this: `left` | Array | The left-hand value. |\n| `right` | Array | The right-hand value. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\nvar empty = ee.Array([], ee.PixelType.int8());\nprint(empty.mod(empty)); // []\n\nprint(ee.Array([0, 0]).mod(ee.Array([-1, 2]))); // [0,0]\nprint(ee.Array([0, 1, 2, 3, 4]).mod(ee.Array([1, 1, 1, 1, 1]))); // [0,0,0,0,0]\nprint(ee.Array([0, 1, 2, 3, 4]).mod(ee.Array([2, 2, 2, 2, 2]))); // [0,1,0,1,0]\nprint(ee.Array([0, 1, 7, 8, 9]).mod(ee.Array([8, 8, 8, 8, 8]))); // [0,1,7,0,1]\nprint(ee.Array([-1, -7, -8, -9]).mod(ee.Array([8, 8, 8, 8]))); // [-1,-7,0,-1]\n\nprint(ee.Array([8, 8, 8, 8]).mod(ee.Array([-1, -7, -8, -9]))); // [0,1,0,8]\n\nprint(ee.Array([2.5]).mod(ee.Array([1.2]))); // [0.10000000000000009]\n\n// Generate a square wave graph using mod.\nvar start = -10;\nvar end = 10;\nvar numElements = 1000;\nvar stepSize = 2;\n\nvar points = ee.Array(ee.List.sequence(start, end, null, numElements));\nvar modValues = ee.Array([stepSize]).repeat(0, numElements);\nvar values = points.mod(modValues).floor();\n\n// Plot mod().floor() defined above.\n// Generate a square wave that is different for negative and positive values.\nvar chart = ui.Chart.array.values(values, 0, points)\n .setOptions({\n viewWindow: {min: start, max: end},\n hAxis: {\n title: 'x',\n viewWindowMode: 'maximized'\n },\n vAxis: {\n title: 'mod().floor()',\n ticks: [{v: -3}, {v: -2}, {v: -1}, {v: 0}, {v: 1}, {v: 2}]\n },\n lineWidth: 1,\n pointSize: 0,\n });\nprint(chart);\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 altair as alt\nimport pandas as pd\n\nempty = ee.Array([], ee.PixelType.int8())\ndisplay(empty.mod(empty)) # []\n\ndisplay(ee.Array([0, 0]).mod(ee.Array([-1, 2]))) # [0,0]\n\n# [0,0,0,0,0]\ndisplay(ee.Array([0, 1, 2, 3, 4]).mod(ee.Array([1, 1, 1, 1, 1])))\n\n# [0,1,0,1,0]\ndisplay(ee.Array([0, 1, 2, 3, 4]).mod(ee.Array([2, 2, 2, 2, 2])))\n\n# [0,1,7,0,1]\ndisplay(ee.Array([0, 1, 7, 8, 9]).mod(ee.Array([8, 8, 8, 8, 8])))\n\n# [-1,-7,0,-1]\ndisplay(ee.Array([-1, -7, -8, -9]).mod(ee.Array([8, 8, 8, 8])))\n\n# [0,1,0,8]\ndisplay(ee.Array([8, 8, 8, 8]).mod(ee.Array([-1, -7, -8, -9])))\n\ndisplay(ee.Array([2.5]).mod(ee.Array([1.2]))) # [0.10000000000000009]\n\n# Generate a square wave graph using mod.\nstart = -10\nend = 10\nnum_elements = 1000\nstep_size = 2\n\npoints = ee.Array(ee.List.sequence(start, end, None, num_elements))\nmod_values = ee.Array([step_size]).repeat(0, num_elements)\nvalues = points.mod(mod_values).floor()\n\ndf = pd.DataFrame({'x': points.getInfo(), 'mod()': values.getInfo()})\n\n# Plot mod().floor() defined above.\n# Generate a square wave that is different for negative and positive values.\nalt.Chart(df).mark_line().encode(\n x=alt.X('x'),\n y=alt.Y('mod()', axis=alt.Axis(values=[-3, -2, -1, 0, 1, 2]))\n)\n```"]]