0

I have 3 unequal arrays that I want to thread together as fast as possible. By threading, I mean, given two arrays, a and b:

a = [1,2]
b = [3,4,5]

I want a new array to be given by

result = [[1,3], [1,4], [1,5], [2,3],[2,4],[2,5]]

or another example

a = 0.5
b = [1,2,3]
result = [[0.5,1],[0.5,2],[0.5,3]]

I could obviously do this with list comprehension like [[i,j] for i in a for j in b] but for large lists on the order of 1000 elements, this takes about 0.3 seconds. I thought the list comprehension wouldn't be so slow but I need this to be much faster, if possible. This looks similar to a tensor product, but I obviously don't want the elements to be multiplied.

shanedrum
  • 129
  • 2

0 Answers0