> a<-matrix(c(1:9),3,3)
> a
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
> a[3,]*a[,3] # I expect 1x1 matrix as result of this.
[1] 21 48 81
> class(a)
[1] "matrix"
> class(a[3,])
[1] "integer"
Run Code Online (Sandbox Code Playgroud)
在R中,1维矩阵变为向量.我可以避免这个吗?我想保留1-D矩阵作为矩阵.实际上,我需要向RcppArmadillo抛出许多种矩阵,甚至是零D矩阵.将矩阵单独更改为向量是我的问题.
这是一个停止循环:
for i in [1,2,3]:
print(i)
if i==3:
break
Run Code Online (Sandbox Code Playgroud)
我怎样才能检查它与它的区别:
for i in [1,2,3]:
print(i)
Run Code Online (Sandbox Code Playgroud)
这是一个想法:
IsBroken=False
for i in [1,2,3]:
print(i)
if i==3:
IsBroken=True
break
if IsBroken==True:
print("for loop was broken")
Run Code Online (Sandbox Code Playgroud) code <- '
arma::mat M=Rcpp::as<arma::mat>(m);
arma::umat a=trans(M)>M;
arma::mat N=a;
return Rcpp::wrap(N);
'
coxFunc <- cxxfunction(signature(m="matrix"),
code,
plugin="RcppArmadillo")
Run Code Online (Sandbox Code Playgroud)
如何在Armadillo上从umat转换为mat?
file53a97e398eed.cpp:33: error: conversion from ‘arma::umat’ to non-scalar type ‘arma::mat’ requested
make: *** [file53a97e398eed.o] Error 1
Run Code Online (Sandbox Code Playgroud)
谢谢,
require(inline)
func <- cxxfunction(, 'return Rcpp::wrap( qnorm(0.95,0.0,1.0) );' ,plugin="Rcpp")
Run Code Online (Sandbox Code Playgroud)
错误:没有用于调用'qnorm5(double,int,int)'的匹配函数
require(inline)
func <- cxxfunction(, 'return Rcpp::wrap( qnorm(0.95, 0.0, 1.0, 1, 0) );'
,plugin="Rcpp")
Run Code Online (Sandbox Code Playgroud)
错误:没有匹配函数来调用'qnorm5(double,double,double,int,int)'
require(inline)
code <-'
double a = qnorm(0.95, 0.0, 1.0);
return Rcpp::wrap( a );
'
func <-
cxxfunction(, code ,plugin="Rcpp")
func()
Run Code Online (Sandbox Code Playgroud)
错误:没有匹配函数来调用'qnorm5(double,double,double)'
如何在Rcpp上使用qnorm?
升级到3.0后,RcppEigen的JacobiSVD变慢了吗?我的图书馆使用RcppEigen现在正在快速工作.
> n<-1000
> m<-matrix(rnorm(n*n),n,n)
> unix.time(s1<-svd(m)) # R
user system elapsed
10.376 0.028 10.407
> unix.time(s2<-svdArma(m)) # RcppArmadillo
user system elapsed
22.997 0.000 23.001
> unix.time(s3<-svdEigen(m)) # RcppEigen
user system elapsed
180.708 0.000 180.712
Run Code Online (Sandbox Code Playgroud)
这是R上的测试代码:
library(inline)
codeArma='
arma::mat m = Rcpp::as<arma::mat>(m_);
arma::mat u;
arma::vec s;
arma::mat v;
arma::svd(u,s,v,m);
return List::create( Rcpp::Named("u")=u,
Rcpp::Named("d")=s,
Rcpp::Named("v")=v );
'
svdArma <- cxxfunction(signature(m_="matrix"),codeArma, plugin="RcppArmadillo")
#-----------------------------------------------------------------------
codeEigen='
const Eigen::Map<Eigen::MatrixXd> m (as<Eigen::Map<Eigen::MatrixXd> >(m_ ));
Eigen::JacobiSVD <Eigen::MatrixXd>svd(m,
Eigen::ComputeThinU|Eigen::ComputeThinV);
return List::create( Rcpp::Named("u")=svd.matrixU(),
Rcpp::Named("d")=svd.singularValues(),
Rcpp::Named("v")=svd.matrixV() );
'
svdEigen <- …
Run Code Online (Sandbox Code Playgroud) 我想创建DB.我有一个脚本文件.sql像这样:
CREATE TABLE [AlleleFreqBySsPop]
(
[subsnp_id] [int] NOT NULL ,
[pop_id] [int] NOT NULL ,
[allele_id] [int] NOT NULL ,
[source] [varchar](2) NOT NULL ,
[cnt] [real] NULL ,
[freq] [real] NULL ,
[last_updated_time] [datetime] NOT NULL
)
GO
Run Code Online (Sandbox Code Playgroud)
它似乎与mysql或postgresql不同.
这是什么类型的语言?我怎么用呢?