numpy - how to use rpy2 to get n-dim array from python -


i want use python calculations , put array data r plot.

for 1-dim array, can use floatvector right answer, n-dim array error

(run following code)

(2-dim array)
import numpy np rpy2.robjects.vectors import floatvector x = np.array([[1, 2], [3, 4]]) x = floatvector(x)

error information:

`traceback (most recent call last):  file "<stdin>", line 1, in <module>  file "d:\program\anaconda3\lib\site-packages\rpy2\robjects\vectors.py",   line 456, in __init__  obj = floatsexpvector(obj)  valueerror: error while trying convert element 0 double.` 

using numpy2ri make error in plot orders(like ggplot2)

i'd doing these in spyder.

the conversion mechanism can friend:

from rpy2.robjects.conversion import localconverter rpy2.robjects import numpy2ri  localconverter(numpy2ri.converter) cv:     x = cv.py2ro(x) # convert *py*thon *ro*bjects 

otherwise, happening because rpy2 trying iterate through sequence x (the default behavior without interaction numpy requested) , make each element through iteration r/rpy2 object. here not work because x[i] turned floatvector , cannot have floatvector of floatvector elements (you have list of floatvector though). explictly, happening (and you'll trigger same error):

floatvector([floatvector(y) y in x]) 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -