[Numpy-discussion] repmat equivalent?

Stefan van der Walt stefan at sun.ac.za
Thu Feb 23 03:58:03 CST 2006


On Thu, Feb 23, 2006 at 01:31:47PM +0200, Albert Strasheim wrote:
> More than 2 dimensions is tricky, since NumPy and MATLAB don't seem to
> agree on how more-dimensional data is organised? As such, I don't know
> what a NumPy user would expect repmat to do with more than 2
> dimensions.

To expand on this, here is what I see when I create (M,N,3) matrices
in both octave and numpy.  I expect to see an MxN matrix stacked 3
high:

octave
------

octave:1> zeros(2,2,3))
ans =

ans(:,:,1) =

  0  0
  0  0

ans(:,:,2) =

  0  0
  0  0

ans(:,:,3) =

  0  0
  0  0

numpy
-----

In [19]: zeros((2,3,3))
Out[19]:
array([[[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]]])


There is nothing wrong with numpy's array -- but the output generated
seems counter-intuitive.

Stéfan




More information about the Numpy-discussion mailing list