ee.Array.bitCount
On an element-wise basis, calculates the number of one-bits in the 64-bit two's complement binary representation of the input.
Usage | Returns |
---|
Array.bitCount() | Array |
Argument | Type | Details |
---|
this: input | Array | The input array. |
Examples
print(ee.Array([], ee.PixelType.int8()).bitCount()); // []
print(ee.Array([0]).bitCount()); // [0]
print(ee.Array([1]).bitCount()); // [1]
print(ee.Array([2]).bitCount()); // [1]
print(ee.Array([3]).bitCount()); // [2]
print(ee.Array([0xFFFF]).bitCount()); // [16]
print(ee.Array([1, 2, 3]).bitCount()); // [1,1,2]
print(ee.Array([[0, 1], [6, 13]]).bitCount()); // [[0,1],[2,3]]
// https://en.wikipedia.org/wiki/Two's_complement signed values.
print(ee.Array([-1]).bitCount()); // [64]
print(ee.Array([-1], ee.PixelType.int8()).bitCount()); // [64]
print(ee.Array([-2]).bitCount()); // [63]
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
display(ee.Array([], ee.PixelType.int8()).bitCount()) # []
display(ee.Array([0]).bitCount()) # [0]
display(ee.Array([1]).bitCount()) # [1]
display(ee.Array([2]).bitCount()) # [1]
display(ee.Array([3]).bitCount()) # [2]
display(ee.Array([0xFFFF]).bitCount()) # [16]
display(ee.Array([1, 2, 3]).bitCount()) # [1, 1, 2]
display(ee.Array([[0, 1], [6, 13]]).bitCount()) # [[0, 1], [2, 3]]
# https://en.wikipedia.org/wiki/Two's_complement signed values.
display(ee.Array([-1]).bitCount()) # [64]
display(ee.Array([-1], ee.PixelType.int8()).bitCount()) # [64]
display(ee.Array([-2]).bitCount()) # [63]
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[[["`Array.bitCount()` calculates the number of 1s in the binary representation of each element in an array."],["It operates on 64-bit two's complement binary representation, supporting both positive and negative integers."],["The function returns an array with the same dimensions as the input, where each element represents the bit count of the corresponding input element."],["This method works for arrays of various data types, including int8, int16, int32, and int64."],["It handles empty arrays, single-element arrays, multi-dimensional arrays, and arrays with both positive and negative numbers."]]],["The `bitCount()` function calculates the number of one-bits in the 64-bit two's complement binary representation of each element in an input array. It operates element-wise and returns a new array with the same shape as the input. The input array can contain positive or negative integers, and the output array provides the one-bit count for each corresponding element. For example, `ee.Array([1, 2, 3]).bitCount()` returns `[1, 1, 2]`.\n"]]