2

In Google Earth Engine, I have two lists:

var list1 = ee.List.sequence(50, 100, 50);
var list2 = ee.List.sequence(2,3,1);

How to make a new list containing every possible pair from list1 to list2 ?

I tried zip() function which gave results as follows: [ [ 50, 2 ], [ 100, 3 ] ].

Pairs [50,3] and [100,2] are missing from this new list. Is there any way out?

4

You could do something like this:

var list1 = ee.List.sequence(50, 100, 50);
var list2 = ee.List.sequence(2,3,1);

var combinations = ee.List(
  list1.iterate(function (e1, acc) {
    var pairs = list2.map(function (e2) {
      return [e1, e2]
    })
    return ee.List(acc).cat(pairs)
  }, ee.List([]))
)
print(combinations)

https://code.earthengine.google.com/9b9ad524cd9a16b1f7dcc2720098aba1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.