Matlab repmat
![matlab repmat matlab repmat](http://1.bp.blogspot.com/-YWfLr3rn4us/UD6vMM43xzI/AAAAAAAAC0w/X3Crk_aANvs/s1600/aa2.png)
I am aware that this reasoning may well not be general, but I could work it out only this far. There, one has to be careful and obtaining the same results with the two languages would require more preconditioning. 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)). These two seemingly equivalent instructions will not produce the same results repmat(L,p,q,r) % matlabīecause the row, column, out-of-plane directions are (p,q,r) in Matlab and (q,r,p) in Python, which was not visible with rank-2 arrays. Here is a much better (official) NumPy for Matlab Users link I’m afraid the mathesaurus one is quite out of date. The game gets trickier when we consider a matrix L of rank 3 (three dimensions) and the simple case of no new dimensions being added in the output matrix. So I would argue that the most general way to move on is to use the ways of np.newaxis. note cumsum done forward order in matlab (1:37) but this is bottom-up in the ocean e.g layer 1 is between -2 deg C and -1. Unless I then precondition M into N as above. The element in in the Python answer for N will contain the same values as the element (:,:,1) the Matlab answer for M.įinally, I can’t seem to find an equivalent for repmat when one uses the Kronecker product out of > np.kron(np.ones((1,1,2)),M).shape I presume this is because we have guided Python to add the third dimension to the right of (2,3) rather than to its left, so that Python works out the sequence (1,1,2) as it was intended in the Matlab way of reading it. Which was the answer of size(repmat(M,1,1,2)). Then, at the input side one has N.shape = (2,3,1) rather than M.shape = (2,3) and at the output side > np.tile(N,(1,1,2)).shape This is done, for example, by a little preconditioning and creating a related object N N = M In order to get tile to behave like repmat, in Python one has to make sure that the input matrix has as many dimensions as the elements are in the sequence. One can no longer assert that repmat and tile are equivalent instructions. 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 2×3, 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.