mmmm... 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/Desktop/NetworkSimulatorTraits/<ipython console> in <module>()

/Library/Frameworks/Python.framework/Versions/4.1.30101/lib/python2.5/site-packages/rpy2/robjects/numpy2ri.pyc
in numpy2ri(o)
     33         # Array-of-PyObject is treated like a Python list:
     34         elif o.dtype.kind == "O":
---> 35             res = ro.conversion.py2ri(list(o))
     36         # Record arrays map onto R data frames:
     37         elif o.dtype.kind == "V":

TypeError: iteration over a 0-d array


I cannot solve it..

simone


2009/1/15 Oliver Tomic <oliver.to...@nofima.no>:
> 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.robjects.numpy2ri
>
>>>> bR = ro.conversion.py2ri(bb)
>
>>>> bR
> <RArray - Python:0x014E7D00 / R:0x0211AFB0>
>
>>>> print bR
> [,1] [,2] [,3]
>
> [1,] NA NA NA
>
> [2,] NA NA NA
> [code END]
>
>
> If you convert the numpy matrix into an array prior to the RPy2-conversion
> it works fine.
> aa = numpy.array(bb)
>
> cheers
> Oliver
>
>
>
> "Simone Gabbriellini" <simone.gabbriell...@gmail.com> wrote on 15.01.2009
> 09:51:30:
>
>> 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:
>>
>> ---------------------------------------------------------------------------
>> RuntimeError                              Traceback (most recent call
>> last)
>>
>> /Users/ogabbrie/Desktop/NetworkSimulatorTraits/<ipython console> in
>> <module>()
>>
>> /Library/Frameworks/Python.framework/Versions/4.1.30101/lib/python2.
>> 5/site-packages/rpy2/robjects/numpy2ri.pyc
>> in numpy2ri(o)
>>      33         # Array-of-PyObject is treated like a Python list:
>>      34         elif o.dtype.kind == "O":
>> ---> 35             res = ro.conversion.py2ri(list(o))
>>      36         # Record arrays map onto R data frames:
>>      37         elif o.dtype.kind == "V":
>>
>> /Library/Frameworks/Python.framework/Versions/4.1.30101/lib/python2.
>> 5/site-packages/rpy2/robjects/numpy2ri.pyc
>> in numpy2ri(o)
>>      47             raise(ValueError("Unknown numpy array type."))
>>      48     else:
>> ---> 49         res = ro.default_py2ri(o)
>>      50     return res
>>      51
>>
>> /Library/Frameworks/Python.framework/Versions/4.1.30101/lib/python2.
>> 5/site-packages/rpy2/robjects/__init__.pyc
>> in default_py2ri(o)
>>      87         res = rinterface.SexpVector([o, ], rinterface.STRSXP)
>>      88     elif isinstance(o, list):
>> ---> 89         res = r.list(*[conversion.ri2py(conversion.py2ri(x))
>> for x in o])
>>      90     elif isinstance(o, complex):
>>      91         res = rinterface.SexpVector([o, ], rinterface.CPLXSXP)
>>
>> RuntimeError: maximum recursion depth exceeded
>>
>>
>> 2009/1/15 Oliver Tomic <oliver.to...@nofima.no>:
>> > 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
>> > <RArray - Python:0x014E7D00 / R:0x0211AF98>
>> >
>> >>>> print aR
>> > [,1] [,2] [,3]
>> >
>> > [1,] 1 2 3
>> >
>> > [2,] 4 5 6
>> >
>> > [code END]
>> >
>> >
>> > cheers
>> > Oliver
>> >
>> >
>> >
>> > Laurent Gautier <lgaut...@gmail.com> wrote on 14.01.2009 23:11:28:
>> >
>> >> 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 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 <simone.gabbriell...@gmail.com>:
>> >> >> [so sorry but I just answer your mail... I write to the list and you
>> >> >> answer to ME and to the list in CC... I have to remember to answer
>> >> >> to
>> >> >> ALL to answer to the mailing list too... again, sorry for that, I
>> >> >> didn't mean to offend you]
>> >> >>
>> >> >> and thanks for the help
>> >> >> simone
>> >> >>
>> >> >> 2009/1/14 Laurent Gautier <lgaut...@gmail.com>:
>> >> >>> [why getting off the list ???]
>> >> >>>
>> >> >>> Simone Gabbriellini wrote:
>> >> >>>> please do you have an example?
>> >> >>>>
>> >> >>>> because when I read "That import alone is sufficient to switch an
>> >> >>>> automatic conversion of numpy objects into rpy2 objects." I
>> >> >>>> suppose
>> >> >>>> that every numpy object is seen by R...
>> >> >>> Automatic conversion of a numpy object:
>> >> >>>
>> >> >>> rlen = robjects.r['length']
>> >> >>> print(rlen(gladj))
>> >> >>>
>> >> >>>
>> >> >>> You are otherwise giving a *string* to be evaluated as R code
>> >> >>> (and R not looking into the python namespace when trying resolvea
>> >> >>> symbol).
>> >> >>> More on evaluating strings here:
>> >> >>> http://rpy.sourceforge.net/rpy2/doc/html/robjects.html?
>> >> highlight=r_repr#strings-as-r-code
>> >> >>>
>> >> >>>> thank you,
>> >> >>>> simone
>> >> >>>>
>> >> >>>> 2009/1/14 Laurent Gautier <lgaut...@gmail.com>:
>> >> >>>>> 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()'))
>> >> >>>>> should confirm that there is no variable 'gladj' in your
>> >> >>>>> globalEnv.
>> >> >>>>>
>> >> >>>>>
>> >> >>>>>> it says:
>> >> >>>>>>
>> >> >>>>>> Error in eval(expr, envir, enclos) : object "g1adj" not found...
>> >> >>>>> The error message above is correct, I think.
>> >> >>>>>
>> >> >>>>>> while
>> >> >>>>>> in the docs it says that:
>> >> >>>>>> "That import alone is sufficient to switch an automatic
>> >> >>>>>> conversion
>> >> >>>>>> of
>> >> >>>>>> numpy objects into rpy2 objects."
>> >> >>>>>>
>> >> >>>>>> should I do something else?
>> >> >>>>>>
>> >> >>>>>> thank you,
>> >> >>>>>> simone
>> >> >>>>>>
>> >> >>>>>> 2009/1/14 Laurent Gautier <lgaut...@gmail.com>:
>> >> >>>>>>> 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 r, while I see how to pass object from r to
>> >> >>>>>>>> python...
>> >> >>>>>>>>
>> >> >>>>>>>> best regards,
>> >> >>>>>>>> Simone Gabbriellini
>> >> >>>>>>>>
>> >> >>>>>>>>
>> >> >>>>>>>>
>> >> >>>>>>>>
>> >> >>>>>>>>
>> >>
>> >>
>>
>> ------------------------------------------------------------------------------
>> >> >>>>>>>> This SF.net email is sponsored by:
>> >> >>>>>>>> SourcForge Community
>> >> >>>>>>>> SourceForge wants to tell your story.
>> >> >>>>>>>> http://p.sf.net/sfu/sf-spreadtheword
>> >> >>>>>>>> _______________________________________________
>> >> >>>>>>>> rpy-list mailing list
>> >> >>>>>>>> rpy-list@lists.sourceforge.net
>> >> >>>>>>>> https://lists.sourceforge.net/lists/listinfo/rpy-list
>> >> >>>>>>
>> >> >>>>>>
>> >>
>> >>
>>
>> ------------------------------------------------------------------------------
>> >> >>>>>> This SF.net email is sponsored by:
>> >> >>>>>> SourcForge Community
>> >> >>>>>> SourceForge wants to tell your story.
>> >> >>>>>> http://p.sf.net/sfu/sf-spreadtheword
>> >> >>>>>> _______________________________________________
>> >> >>>>>> rpy-list mailing list
>> >> >>>>>> rpy-list@lists.sourceforge.net
>> >> >>>>>> https://lists.sourceforge.net/lists/listinfo/rpy-list
>> >> >>>
>> >> >
>> >> >
>> >>
>> >>
>>
>> ------------------------------------------------------------------------------
>> >> > This SF.net email is sponsored by:
>> >> > SourcForge Community
>> >> > SourceForge wants to tell your story.
>> >> > http://p.sf.net/sfu/sf-spreadtheword
>> >> > _______________________________________________
>> >> > rpy-list mailing list
>> >> > rpy-list@lists.sourceforge.net
>> >> > https://lists.sourceforge.net/lists/listinfo/rpy-list
>> >>
>> >>
>> >>
>> >>
>>
>> ------------------------------------------------------------------------------
>> >> This SF.net email is sponsored by:
>> >> SourcForge Community
>> >> SourceForge wants to tell your story.
>> >> http://p.sf.net/sfu/sf-spreadtheword
>> >> _______________________________________________
>> >> rpy-list mailing list
>> >> rpy-list@lists.sourceforge.net
>> >> https://lists.sourceforge.net/lists/listinfo/rpy-list
>> >
>

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to