[Numpy-discussion] repmat equivalent?
fullung at gmail.com
Thu Feb 23 12:12:06 CST 2006
On 2/23/06, Christopher Barker <Chris.Barker at noaa.gov> wrote:
> Albert Strasheim wrote:
> > There are other (unexpected, for me at least) differences between
> > MATLAB/Octave and NumPy too.
> First: numpy is not, and was never intended to be, a MATLAB clone,
> work-alike, whatever. You should *expect* there to be differences.
I understand this. As a new user, I'm trying to understand these differences.
> > For a 3D array in MATLAB, only indexing
> > on the last dimension yields a 2D array, where NumPy always returns a
> > 2D array.
> I think the key here is that MATLAB's core data type is a matrix, which
> is 2-d. The ability to do 3-d arrays was added later, and it looks like
> they are still preserving the core matrix concept, so that a 3-d array
> is not really a 3-d array; it is, as someone on this thread mentioned, a
> "stack" of matrices.
> In numpy, the core data type is an n-d array. That means that there is
> nothing special about 2-d vs 4-d vs whatever, except 0-d (scalars). So a
> 3-d array is a cube shape, that you might want to pull a 2-d array out
> of it in any orientation. There's nothing special about which axis
> you're indexing. For that reason, it's very important that indexing any
> axis will give you the same rank array.
> Here's the rule:
> -- indexing reduces the rank by 1, regardless of which axis is being
Thanks for your comments. These cleared up a few questions I had about
NumPy's design. However, I'm still wondering how the average NumPy
user would expect repmat implemented for NumPy to behave with arrays
with more than 2 dimensions.
I would like to clear this up, since I think that a good repmat
function is an essential tool for implementing algorithms that use
matrix multiplication instead of for loops to perform operations
(hopefully with a significant speed increase). If there is another way
of accomplishing this, I would love to know.
More information about the Numpy-discussion