[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: creation of a permutation matrix (WAS: Re: remove for-loop from foll
From: |
c. |
Subject: |
Re: creation of a permutation matrix (WAS: Re: remove for-loop from following code) |
Date: |
Sun, 6 Nov 2011 18:04:59 +0100 |
On 6 Nov 2011, at 13:30, Juan Pablo Carbajal wrote:
>
> Hi,
>
> Indeed, you get the permutation matrix if you use K=max(Y). If you
> just want a submatrix out of the full permutation matrix, I think the
> only solution to save storage is using a sparse matrix. right?
>
or a a rectangular diagonal matrix times a square permutation matrix:
>> P = eye (4) ([1 3 2 4], :)
P =
Permutation Matrix
1 0 0 0
0 0 1 0
0 1 0 0
0 0 0 1
>> C = diag (ones (3, 1), 3, 4)
C =
Diagonal Matrix
1 0 0 0
0 1 0 0
0 0 1 0
>> whos P C
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
P 4x4 16 double
C 3x4 24 double
Total is 28 elements using 40 bytes
>>
though one then must be careful to compute C * P * X as C * (P * X) and not (C
* P) * X
to avoid creating a full matrix again
c.