Simone Gabbriellini wrote:
> Dear List,
>
> sorry, but it's me again, because I still cannot figure out how to do
> this thing...
>
> I have my matrix in R as a numpy.array, everything is ok:
>
> In [35]: mymatrixR
> Out[35]:
>
> now I want to put mymatrixR inside the R object QAP, something l
Dear List,
sorry, but it's me again, because I still cannot figure out how to do
this thing...
I have my matrix in R as a numpy.array, everything is ok:
In [35]: mymatrixR
Out[35]:
now I want to put mymatrixR inside the R object QAP, something like
QAPset[,,1]<-mymatrixR
if I simply do:
rob
You are right, I was doing a bad conversion of the matrix to the numpy.array...
in fact the result of what you ask was:
Out[56]: ()
now everything works because I do:
mymatrixN = numpy.array(list(mymatrix))
and now if I run numpy.shape I have:
Out[56]: (50,50)
I got the hint from the author of
... if I convert the matrix into array I have this new error:
In [41]: mymatrixR = ro.conversion.py2ri(mymatrixNARRAY)
---
TypeError Traceback (most recent call last)
/Users/ogabbrie/Deskto
The conversion doesn't work for me with matrices either, but the output is
different on my machine.
This is what I get:
[code START]
>>> import numpy
>>> b = [[1,2,3],[4,5,6]]
>>>bb = numpy.matrix(b)
>>> bb
matrix([[1, 2, 3],
[4, 5, 6]])
>>> import rpy2.robjects as ro
>>> import rpy2
Hi Oliver,
yes this helps very much... anyway, this works with array or also with matrix?
I ask this because I have a matrix 50x50, and if I do:
mymatrixNump = numpy.matrix(mymatrix)
mymatrixR = ro.conversion.py2ri(mymatrixNump)
I have:
--
Hi Simone,
maybe this helps:
[code START]
>>> import numpy
>>> a = [[1,2,3],[4,5,6]]
>>> aa = numpy.array(a)
>>> aa
array([[1, 2, 3],
[4, 5, 6]])
>>> import rpy2.robjects as ro
>>> import rpy2.robjects.numpy2ri
>>> aR = ro.conversion.py2ri(aa)
>>> aR
>>> print aR
[,1] [,2] [,
Simone Gabbriellini wrote:
> I would like to know if there is something like r.assign('ROBJECT',
> PYTHONOBJECT) in rpy2...
http://rpy.sourceforge.net/rpy2/doc/html/robjects.html?highlight=assign#environments
Or "assign" as you write above:
r.assign("foo", 123)
> I don't want to use R function
I would like to know if there is something like r.assign('ROBJECT',
PYTHONOBJECT) in rpy2...
I don't want to use R function to evaluate an object IN Python, I want
to assign a matrix made in python to an R object...
simone
2009/1/14 Simone Gabbriellini :
> [so sorry but I just answer your mail..
Simone Gabbriellini wrote:
> yes, like that...
>
> but simply importing:
>
> Import rpy2.robjects.numpy2ri
>
> when I do:
>
> g1adj = numpy.array(g1adj)
>
> robjects.r('QAPset[1,,]<-g1adj')
R has no way to know your Python variable called "gladj" unless you
indicate it.
print(robjects.r('ls
yes, like that...
but simply importing:
Import rpy2.robjects.numpy2ri
when I do:
g1adj = numpy.array(g1adj)
robjects.r('QAPset[1,,]<-g1adj')
it says:
Error in eval(expr, envir, enclos) : object "g1adj" not found... while
in the docs it says that:
"That import alone is sufficient to switch an
Something like this
http://rpy.sourceforge.net/rpy2/doc/html/numpy.html?highlight=numpy
?
Simone Gabbriellini wrote:
> dear List,
>
> is it possible to pass a matrix I've built in python to R via rpy2?
>
> I'm sure I'm blind, but I cannot find example about how to pass object
> from python to
dear List,
is it possible to pass a matrix I've built in python to R via rpy2?
I'm sure I'm blind, but I cannot find example about how to pass object
from python to r, while I see how to pass object from r to python...
best regards,
Simone Gabbriellini
--
13 matches
Mail list logo