it is clear to me how to convert a float / double R-matrix into a numpy array, but I get an error if the matrix is complex.
Example:
import numpy as np
import rpy2.robjects as robjects
import rpy2.robjects.numpy2ri
rpy2.robjects.numpy2ri.activate()
m1=robjects.IntVector(range(10))
m2 = robjects.r.matrix(robjects.r['as.complex'](m1), nrow=5)
tmp=np.array(m2, dtype=complex) #ValueError: invalid __array_struct__
The problem persists with the following line of code:
tmp=np.array(m2)
All works fine if the matrix is not complex:
m2 = robjects.r.matrix(m1, nrow=5)
tmp=np.array(m2)
Thanks for any help!
PS: Note that the following dirty trick solves the problem, but does not really answer the question:
tmp=np.array(robjects.r.Re(m2))+1j*np.array(robjects.r.Im(m2))
PS2: it seems that nobody can answer this question, should we conclude there is a bug in rpy2?