[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to create a permutation matrix
From: |
c. |
Subject: |
Re: how to create a permutation matrix |
Date: |
Tue, 27 Jan 2015 07:29:53 +0100 |
On 26 Jan 2015, at 19:57, Jordi Gutiérrez Hermoso <address@hidden> wrote:
> On Mon, 2015-01-26 at 18:58 +0100, c. wrote:
>> Is it expected that :
>>
>>>> P = eye (4);
>>>> P = P([2 1 3 4], :);
>>>> typeinfo (P)
>> ans = permutation matrix
>>
>> but
>>
>>>> P = eye (4);
>>>> P ([1 2], :) = P([2 1], :);
>>>> typeinfo (P)
>> ans = matrix
>
> Yes, that's the current implementation. You need to specify the full
> permutation vector in order to get a permutation matrix. It would take
> a bit more magic to realise that P([2 1], :) is being assigned to a
> permuted version of itself and thus create a permutation matrix.
Wouldn't it be better to at least fall back to SparseMatrix rather than Matrix
in this case?
> - Jordi G. H.
c.