Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 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```"]]