
The resulting object has a different shape from Matlab. The number of copies in the direction of columns, rows and out-of-plane dimension are being read from right to left. It has applied a different procedure since, I presume, the sequence (1,1,2) is read differently than in Matlab. True to the naming repmat for repeat matrix. It has copied the first two dimensions (rows and columns) of the input matrix and has repeated that once into a new third dimension (copied twice, that is). Say the sequence for manipulation is now 1,1,2. Going back to the matrix M of rank two and shape 2x3, it is sufficient to look at what happens to the size/shape of the output matrix.

The matters goes counter-intuitive when you ask for repetition/tiling over more dimensions than the input matrix has. Thus the two commands repmat(M,m,n) % matlabĪre really equivalent for a matrix of rank 2 (two dimensions). I could see no difference between Matlab and Python while asking to manipulate the input matrix along the dimensions the matrix already has. Happy to be corrected and hope this helps. This is how I understood it out of a bit of fiddling around.

So if you had, say, a 1600x1400x3 array representing a 3-color image, you could (elementwise) multiply it by to reduce the amount of green and blue at each pixel.

Note that some of the reasons you'd need to use MATLAB's repmat are taken care of by NumPy's broadcasting mechanism, which allows you to do various types of math with arrays of similar shape. (Numpy gives a 3d output array as you would expect - matlab for some reason gives 2d output - but the content is the same).

This works with multiple dimensions and gives a similar result to matlab. The numpy equivalent of repmat(a, m, n) is tile(a, (m, n)). Here is a much better (official) NumPy for Matlab Users link - I'm afraid the mathesaurus one is quite out of date.
