Hi,

try the following:

from rpy import *
r('mat = matrix(1:25, 5, 5)')
[[1, 6, 11, 16, 21], [2, 7, 12, 17, 22], [3, 8, 13, 18, 23], [4, 9, 14, 19, 24], [5, 10, 15, 20, 25]]
r('mat[1,1] = 100')
100.0
r('mat')
[[100.0, 6.0, 11.0, 16.0, 21.0], [2.0, 7.0, 12.0, 17.0, 22.0], [3.0, 8.0, 13.0, 18.0, 23.0], [4.0, 9.0, 14.0, 19.0, 24.0], [5.0, 10.0, 15.0, 20.0, 25.0]]
r.library('SparseM')
r('Mcsr = as.matrix.csr(mat)')
<Robj object at 0x0096C3B0>
r.print_(r.Mcsr)
An object of class "matrix.csr"
Slot "ra":
[1] 100 6 11 16 21 2 7 12 17 22 3 8 13 18 23 4 9 14 19
[20]  24   5  10  15  20  25

Slot "ja":
[1] 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5

Slot "ia":
[1]  1  6 11 16 21 26

Slot "dimension":
[1] 5 5

<Robj object at 0x0096C3A0>
ra = r.slot(r.Mcsr, 'ra')
ra
[100.0, 6.0, 11.0, 16.0, 21.0, 2.0, 7.0, 12.0, 17.0, 22.0, 3.0, 8.0, 13.0, 18.0, 23.0, 4.0, 9.0, 14.0, 19.0, 24.0, 5.0, 10.0, 15.0, 20.0, 25.0]


HTH,

amsantac





From: "WR -" <[EMAIL PROTECTED]>
Reply-To: "RPy help, support and design discussion list" <rpy-list@lists.sourceforge.net>
To: rpy-list@lists.sourceforge.net
Subject: [Rpy] RPY SPARSE and Matrix
Date: Mon, 30 Apr 2007 19:22:15 +0200

I’m going to use SparseMatrices. For these SparseMatrices I’m using the R
module SparseM.

There are some problems by converting SparseMatrices. Maby there is an easy
solution. But at the moment I can’t found it. Before starting I read the RPY
Reference Manual. The Manual is not complete enough to answer my questions.

Code:
-----------------------------------------------------------------------------------
from rpy import *
r.library('SparseM')

set_default_mode(NO_CONVERSION)

r.m = r.matrix(range(1,26), 5, 5)
r.print_(r.m)
-----------------------------------------------------------------------------------

How is it possible to declarate/subscript a value to the matrix without
conversion?
e.g.: r.m[1,1] = 100, r(r.m[1,1] <- 100, r.m[1][1] = 100)
Not working in RPY, get errors like:

IndexError: R object index out of range
TypeError: sequence index must be integer

After generating this matrix I convert the matrix to a SparseMatrix

-----------------------------------------------------------------------------------
r.M_csr = r.as_matrix_csr(r.m)
r.print_(r.M_csr)
-----------------------------------------------------------------------------------

I use the slots to get the information:
Why I can’t use[1,2] like below.
In R-console [1,2] works fine. Did I need a Conversion?
I don’t think so its a Robj object……
-----------------------------------------------------------------------------------
ra = r.slot(r.M_csr, 'ra')
ra2 = r.slot(r.M_csr[1,2], 'ra')
-----------------------------------------------------------------------------------


Thanks for your time!

_________________________________________________________________
Eindeloos zoeken naar dat ene document is nu voorbij! Klik hier
http://toolbar.live.com


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to