rpy2 how to call as.matrix()
up vote
0
down vote
favorite
I am using rpy2 to call some R function from python. The R function returns a dist object. How do I call as.matrix()
from python on the result the R code returns?
import rpy2.robjects.numpy2ri
from rpy2.robjects.packages import importr
rpy2.robjects.numpy2ri.activate()
Rsession = rpy2.robjects.r
tsclust = importr('TSclust')
X= np.random.random((5,5))
result = Rsession.diss( X , "ACF", p=0.05)
result
is of the class dist. I would like a square distance matrix, which I can achieve by calling as.matrix()
on the result . How do I do this with rpy2?
rpy2
add a comment |
up vote
0
down vote
favorite
I am using rpy2 to call some R function from python. The R function returns a dist object. How do I call as.matrix()
from python on the result the R code returns?
import rpy2.robjects.numpy2ri
from rpy2.robjects.packages import importr
rpy2.robjects.numpy2ri.activate()
Rsession = rpy2.robjects.r
tsclust = importr('TSclust')
X= np.random.random((5,5))
result = Rsession.diss( X , "ACF", p=0.05)
result
is of the class dist. I would like a square distance matrix, which I can achieve by calling as.matrix()
on the result . How do I do this with rpy2?
rpy2
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am using rpy2 to call some R function from python. The R function returns a dist object. How do I call as.matrix()
from python on the result the R code returns?
import rpy2.robjects.numpy2ri
from rpy2.robjects.packages import importr
rpy2.robjects.numpy2ri.activate()
Rsession = rpy2.robjects.r
tsclust = importr('TSclust')
X= np.random.random((5,5))
result = Rsession.diss( X , "ACF", p=0.05)
result
is of the class dist. I would like a square distance matrix, which I can achieve by calling as.matrix()
on the result . How do I do this with rpy2?
rpy2
I am using rpy2 to call some R function from python. The R function returns a dist object. How do I call as.matrix()
from python on the result the R code returns?
import rpy2.robjects.numpy2ri
from rpy2.robjects.packages import importr
rpy2.robjects.numpy2ri.activate()
Rsession = rpy2.robjects.r
tsclust = importr('TSclust')
X= np.random.random((5,5))
result = Rsession.diss( X , "ACF", p=0.05)
result
is of the class dist. I would like a square distance matrix, which I can achieve by calling as.matrix()
on the result . How do I do this with rpy2?
rpy2
rpy2
asked Nov 21 at 18:54
benbo
602619
602619
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I figured out one solution. It's not pretty but it works. We define a custom function that calls as.matrix
from rpy2.robjects.packages import STAP
mfunc = 'myasmatrix <- function(dobj){return(as.matrix(dobj))}'
myasmatrix = STAP(mfunc, "myasmatrix")
np.array(myasmatrix.myasmatrix(rres))
>>> array([[0. , 0.0663193 , 0.01159857, 0.14378692, 0.10069314],
[0.0663193 , 0. , 0.06064907, 0.07965314, 0.03511945],
[0.01159857, 0.06064907, 0. , 0.13898505, 0.095319 ],
[0.14378692, 0.07965314, 0.13898505, 0. , 0.04757353],
[0.10069314, 0.03511945, 0.095319 , 0.04757353, 0. ]])
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I figured out one solution. It's not pretty but it works. We define a custom function that calls as.matrix
from rpy2.robjects.packages import STAP
mfunc = 'myasmatrix <- function(dobj){return(as.matrix(dobj))}'
myasmatrix = STAP(mfunc, "myasmatrix")
np.array(myasmatrix.myasmatrix(rres))
>>> array([[0. , 0.0663193 , 0.01159857, 0.14378692, 0.10069314],
[0.0663193 , 0. , 0.06064907, 0.07965314, 0.03511945],
[0.01159857, 0.06064907, 0. , 0.13898505, 0.095319 ],
[0.14378692, 0.07965314, 0.13898505, 0. , 0.04757353],
[0.10069314, 0.03511945, 0.095319 , 0.04757353, 0. ]])
add a comment |
up vote
0
down vote
I figured out one solution. It's not pretty but it works. We define a custom function that calls as.matrix
from rpy2.robjects.packages import STAP
mfunc = 'myasmatrix <- function(dobj){return(as.matrix(dobj))}'
myasmatrix = STAP(mfunc, "myasmatrix")
np.array(myasmatrix.myasmatrix(rres))
>>> array([[0. , 0.0663193 , 0.01159857, 0.14378692, 0.10069314],
[0.0663193 , 0. , 0.06064907, 0.07965314, 0.03511945],
[0.01159857, 0.06064907, 0. , 0.13898505, 0.095319 ],
[0.14378692, 0.07965314, 0.13898505, 0. , 0.04757353],
[0.10069314, 0.03511945, 0.095319 , 0.04757353, 0. ]])
add a comment |
up vote
0
down vote
up vote
0
down vote
I figured out one solution. It's not pretty but it works. We define a custom function that calls as.matrix
from rpy2.robjects.packages import STAP
mfunc = 'myasmatrix <- function(dobj){return(as.matrix(dobj))}'
myasmatrix = STAP(mfunc, "myasmatrix")
np.array(myasmatrix.myasmatrix(rres))
>>> array([[0. , 0.0663193 , 0.01159857, 0.14378692, 0.10069314],
[0.0663193 , 0. , 0.06064907, 0.07965314, 0.03511945],
[0.01159857, 0.06064907, 0. , 0.13898505, 0.095319 ],
[0.14378692, 0.07965314, 0.13898505, 0. , 0.04757353],
[0.10069314, 0.03511945, 0.095319 , 0.04757353, 0. ]])
I figured out one solution. It's not pretty but it works. We define a custom function that calls as.matrix
from rpy2.robjects.packages import STAP
mfunc = 'myasmatrix <- function(dobj){return(as.matrix(dobj))}'
myasmatrix = STAP(mfunc, "myasmatrix")
np.array(myasmatrix.myasmatrix(rres))
>>> array([[0. , 0.0663193 , 0.01159857, 0.14378692, 0.10069314],
[0.0663193 , 0. , 0.06064907, 0.07965314, 0.03511945],
[0.01159857, 0.06064907, 0. , 0.13898505, 0.095319 ],
[0.14378692, 0.07965314, 0.13898505, 0. , 0.04757353],
[0.10069314, 0.03511945, 0.095319 , 0.04757353, 0. ]])
answered Nov 21 at 19:05
benbo
602619
602619
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418818%2frpy2-how-to-call-as-matrix%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown