[SciPy-user] In-place matrix reordering

Antonino Ingargiola tritemio at gmail.com
Wed Feb 25 05:31:25 EST 2009


2009/2/25 Robert Kern <robert.kern at gmail.com>:
> On Wed, Feb 25, 2009 at 02:12, Antonino Ingargiola <tritemio at gmail.com> wrote:
>> Hi to the list,
>>
>> I have to "reorder" the columns of a big 2D array (a matrix) but
>> without doing a temp copy of the whole matrix (since it is 1.5GB).
>>
>> Basically I would need something like this:
>>
>> a = arange(12).reshape(4,3)
>> b = a[:,(2,0,1)]
>>
>> but without the array copy triggered by the advanced indexing. Let the
>> (2,0,1) tuple be an arbitrary sequence previously computed.
>>
>> The .take method seems to do a copy too:
>>
>> b = a.take((2,0,1), axis=1)
>>
>> What I need is a "view" of "a" with an arbitrary column order.
>>
>> Is there a way to accomplish this task?
>
> No, sorry. numpy's memory model does not allow arbitrary views like this.

Is there any workarounds to save ram in this case? Something like
using an external package or inline C (I have no idea about that).

Thanks,

   ~ Antonio



More information about the SciPy-User mailing list