ee.Array.dotProduct

  • Computes the dot product of two 1-D arrays.

  • Takes two arrays as input and returns a single number.

Compute the dot product between two 1-D arrays.

UsageReturns
Array.dotProduct(array2)Number
ArgumentTypeDetails
this: array1ArrayThe first 1-D array.
array2ArrayThe second 1-D array.

Examples

Code Editor (JavaScript)

print(ee.Array([1]).dotProduct(ee.Array([2])));  // 2
print(ee.Array([1, 2]).dotProduct(ee.Array([3, 4])));  // 1*3 + 2*4 = 11
print(ee.Array([0, 1, 2]).dotProduct(ee.Array([3, 4, 5])));  // 0*3 + 1*4 + 2*5 = 14
print(ee.Array([-1, -2]).dotProduct(ee.Array([3, 4])));  // -1*3 + -2*4 = -11
print(ee.Array([1.5, 2.5]).dotProduct(ee.Array([3, 4])));  // 1.5*3 + 2.5*4 = 14.5

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)

display(ee.Array([1]).dotProduct(ee.Array([2])).getInfo())  # 2
display(ee.Array([1, 2]).dotProduct(ee.Array([3, 4])).getInfo())  # 1*3 + 2*4 = 11
display(ee.Array([0, 1, 2]).dotProduct(ee.Array([3, 4, 5])).getInfo())  # 0*3 + 1*4 + 2*5 = 14
display(ee.Array([-1, -2]).dotProduct(ee.Array([3, 4])).getInfo())  # -1*3 + -2*4 = -11
display(ee.Array([1.5, 2.5]).dotProduct(ee.Array([3, 4])).getInfo())  # 1.5*3 + 2.5*4 = 14.5