Good day.

I have a problem with matrices / arrays, i cannot resolve. I have no idea how to start...

I have two 2D matrices and i want to overlap (mix?) one over the other, no matter what dimensions they have.

For example :

a = [ (1,2,3,4,5),

(9,7),

(0,0,0,0,0),

(5,5,5) ]

b = [ (0,0,0),

(1,1,1,1),

(2,2,2,2) ]

Now, if i want to put a over b, i get the result:

a over b = [

(1,2,3,4,5),

(9,7,1,1),

(0,0,0,0,0),

(5,5,5,2) ]

And b over a = [

(0,0,0,4,5),

(1,1,1,1),

(0,0,0,0,0),

(2,2,2,2) ]

I think this operation has a name in mathematics, but i don't know how to call it... and what to search for.

I tried 2 days to make a good algorithm and i gave up... **Please keep in mind that my matrices are not square or rectangle**. They can be very nasty to combine.

In fact, there is an undefined number of matrices i need to overlap, all this overlaping is in a strict order. I suppose that if i have the algorithm for 2 matrices, i can make a big "for" cicle and mix the next matrix over the previous result.

I need this overlap to happen AS FAST AS POSSIBLE. I need to overlap matrices with milions of elements, like 1600x1200.

Any help is welcome. Thank you very much.