Solved by jpeg729 in post #14 
              
              
                So basically, you concatenate a and b along the first dimension, and then take all pairings along that first dimension. 
If so, my previous code can be adapted to do the job.