[Numpy-discussion] Reshaing continued

Rob Hooft rob at hooft.net
Sun Sep 12 11:49:00 EDT 2004


Karthikesh Raju wrote:
> A partial support for 3D has been by extending the number of columns in a
> 2D matrix, so each new dimension is a block matrix in the columns. This
> works fine, but again another day when i need 4D it would break. This is
> why i thought i could play with reshape to get things correct once and for
> all.

I am answering from rusty Numeric knowledge, not knowing whether the 
numarray implementation is different.

I think you are mixing up how reshape and how transpose work.

"reshape" doesn't actually touch the data; it only changes the size of 
the different dimensions. Therefore, the order of the data in the array 
can not be changed by reshape, nor can the number of data points.

The transpose method also doesn't touch the actual data, but it changes 
the strides in which the data are used. transpose can change the order 
of N-dimensions, not only 2!

Both operations are basically O(1), which practically means that they 
are instantaneous, no matter how large the arrays.

After a transpose, the array is normally non-contiguous, which might 
mean that repeated walk-throughs are significantly slower, and it may 
pay to make a contiguous copy first.

Rob

-- 
Rob W.W. Hooft  ||  rob at hooft.net  ||  http://www.hooft.net/people/rob/




More information about the NumPy-Discussion mailing list