python - Convert numpy matrix to R matrix and keep it that way -


i'd convert numpy matrix r matrix. i'm aware this:

from rpy2 import robjects ro ro.conversion.py2ri = ro.numpy2ri ro.numpy2ri.activate() 

and build r matrix:

mat_r = ro.r.matrix(mat_py) 

but problem is, whenever refer new matrix in python gets converted numpy matrix. instance, need set row , column names, doing results in this:

mat_r.rownames = numpy.array([1,2,3]) attributeerror: 'numpy.ndarray' object has no attribute 'rownames' 

anyone know how can keep shiny new r matrix r matrix, , stop becoming ndarray again?

one way might be

ro.numpy2ri.deactivate() 

the conversion can called explicitly (the conversion generics in module, here numpy2ri).


Comments

Popular posts from this blog

python - How to create jsonb index using GIN on SQLAlchemy? -

PHP DOM loadHTML() method unusual warning -

c# - TransactionScope not rolling back although no complete() is called -