ee.Array.byte

On an element-wise basis, casts the input value to an unsigned 8-bit integer.

UsageReturns
Array.byte()Array
ArgumentTypeDetails
this: inputArrayThe 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 [[], []]

Python setup

See the Python Environment page for information on the Python API and using geemap for interactive development.

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())  # [[], []]