AI-generated Key Takeaways
-
The
byte()method casts input values to an unsigned 8-bit integer on an element-wise basis. -
Values below 0 are clamped to 0, and values above 255 are clamped to 255.
-
The
byte()method rounds input values. -
An explicit
PixelTypeis required if there is no data in the input array.
| Usage | Returns |
|---|---|
Array.byte() | Array |
| Argument | Type | Details |
|---|---|---|
this: input | Array | The input array. |
Examples
Code Editor (JavaScript)
// Clamps below at 0. print(ee.Array([-1]).byte()); // [0] print(ee.Array([255]).byte()); // [255] // Clamps above at 255. print(ee.Array([256]).byte()); // [255] // Rounds. [0,0,1,127,255,255] print(ee.Array([-0.1, 0.1, 0.5, 127.1, 255.1, 255.9]).byte()); // Requires an explicit PixelType if no data. print(ee.Array([[], []], ee.PixelType.float()).byte()); // Empty [[], []]
import ee import geemap.core as geemap
Colab (Python)
# Clamps below at 0. display(ee.Array([-1]).byte()) # [0] display(ee.Array([255]).byte()) # [255] # Clamps above at 255. display(ee.Array([256]).byte()) # [255] # Rounds. [0, 0, 1, 127, 255, 255] display(ee.Array([-0.1, 0.1, 0.5, 127.1, 255.1, 255.9]).byte()) # Requires an explicit PixelType if no data. display(ee.Array([[], []], ee.PixelType.float()).byte()) # [[], []]