我试图将一个可变长度的字符串列表存储到HDF5数据集.这个代码是
import h5py
h5File=h5py.File('xxx.h5','w')
strList=['asas','asas','asas']
h5File.create_dataset('xxx',(len(strList),1),'S10',strList)
h5File.flush()
h5File.Close()
Run Code Online (Sandbox Code Playgroud)
我收到一个错误,指出"TypeError:没有dtype的转换路径:dtype('< U3')"其中<表示实际小于符号
我该如何解决这个问题.
我引用"当进程使用fork()调用创建一个新进程时,只有父进程和新分叉的子进程之间共享共享内存段.堆栈和堆的副本是为新创建的进程"从Silberschatz的"操作系统概念"解决方案.
但是当我尝试这个程序的时候
#include <stdio.h>
#include <sys/types.h>
#define MAX_COUNT 200
void ChildProcess(void); /* child process prototype */
void ParentProcess(void); /* parent process prototype */
void main(void)
{
pid_t pid;
char * x=(char *)malloc(10);
pid = fork();
if (pid == 0)
ChildProcess();
else
ParentProcess();
printf("the address is %p\n",x);
}
void ChildProcess(void)
{
printf(" *** Child process ***\n");
}
void ParentProcess(void)
{
printf("*** Parent*****\n");
}
Run Code Online (Sandbox Code Playgroud)
结果如下:
*** Parent*****
the address is 0x1370010
*** Child process ***
the address is 0x1370010
Run Code Online (Sandbox Code Playgroud)
父和子两者都打印堆中的相同地址.
谁能解释我这里的矛盾.请清楚说明父母和孩子在内存空间中共享的所有内容.
我正在尝试在C ++中的R中分别为Vector,Matrix和Data Frame实现本机拆分功能。例如下面的功能用于拆分矢量。
using namespace Rcpp;
using namespace std;
//[[Rcpp::export]]
List splitVecCpp(NumericVector x, NumericVector y) {
std::map<double,NumericVector> output;
for (int i=0;i<x.size();i++) {
output[ y[i] ].push_back(x[i]);
}
return wrap(output);
}
Run Code Online (Sandbox Code Playgroud)
但这甚至比本地拆分功能要慢。我认为push_back函数会使上述版本变慢,因为它会为每次后推重新分配向量。但我不确定。欢迎任何建议和解释。
接下来矩阵的分割功能如下
//[[Rcpp::export]]
std::map<double,std::set<int> > uniqueCpp(NumericVector x){
std::map<double,std::set<int> > out;
for(int i=0;i<x.length();i++){
if(out.count(x[i])){
std::set<int> temp_set=out.find(x[i])->second;
temp_set.insert(i);
out[x[i]]=temp_set;
}else{
std::set<int> temp_set;
temp_set.insert(i);
out[x[i]]=temp_set;
}
}
return out;
}
//[[Rcpp::export]]
List splitMatCpp(NumericMatrix splited,NumericVector spliter){
std::map<double,std::set<int> > uniqueSpliter=uniqueCpp(spliter);
std::map<double,NumericMatrix> output;
for(std::map<double , std::set<int> >::iterator it=uniqueSpliter.begin();it!=uniqueSpliter.end();++it){
std::set<int> indices=it->second;
NumericMatrix temp_mat(indices.size(),splited.ncol());
int j=0;
for(std::set<int>::iterator index_it=indices.begin();index_it!=indices.end();++index_it){
temp_mat(j,_)=splited(*index_it,_); …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用Rcpp在c ++中获得向量的等级.我使用过其他糖功能
is_na();
Run Code Online (Sandbox Code Playgroud)
c ++中的等级R函数是否有类似的糖函数.还有Rcpp中可用的R糖功能列表/
到目前为止,我一直在尝试在 Rcpp 中实现应用功能,代码如下所示
//[[Rcpp::export]]
NumericVector apply(NumericMatrix x,int dim,Function f){
NumericVector output;
if(dim==1){
for(int i=0;i<x.nrow();i++){
output[i]=f(x(i,_));
}
}
else if(dim==2){
for(int i=0;i<x.ncol();i++){
output[i]=f(x(_,i));
}
}
return(output);
}
Run Code Online (Sandbox Code Playgroud)
但我在第 6 行和第 11 行收到错误“无法将 SEXP 转换为赋值中的双精度值”。有没有办法将任意函数返回的值转换为双精度值?应用函数也有一个糖函数。
有一种方法可以用NA值初始化数值向量.
NumericVector x(10,NumericVector::get_na())
Run Code Online (Sandbox Code Playgroud)
是否有任何类似的方法将矩阵初始化为NA值?
我试图从画廊或拍摄的相机中显示图像ImageView.我开始接受OOM这个过程.所以我决定找出它是如何工作的.所以我尝试了不同尺寸的图像,这里是观察,
我试图加载一个19KB的图像,ImageView并得到以下错误信息.无法分配4915212字节分配570452空闲字节和557KB直到OOM2MB映像我无法分配31961100字节分配16777120空闲字节和29MB直到OOM2MB
为什么19KB图像需要大约4.6MB的主内存和2MB图像需要30 MB的主内存空间?
PS:我发现很多解决方案,比如根据显示器对图像进行下采样,但没有一个解释这种行为.
我正在尝试使用 Rstudio 在 Windows 系统中设置 RcppArmadillo。我已经使用命令成功安装了 RcppArmadillo
install.packages("RcppArmadillo")
Run Code Online (Sandbox Code Playgroud)
在 R 控制台中。
但是当我尝试使用 RcppArmadillo 依赖项编译 C++ 代码时,我收到如下错误
g++ -m64 -I"C:/PROGRA~1/R/R-30~1.3/include" -DNDEBUG -I"C:/PROGRA~1/R/R-30~1.3/library/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c colrowStat.cpp -o colrowStat.o colrowStat.cpp:5:26: fatal error: RcppArmadillo.h: No such file or directory compilation terminated. make: *** [colrowStat.o] Error 1 Warning message: running command 'make -f "C:/PROGRA~1/R/R-30~1.3/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-30~1.3/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_38187.dll" WIN=64 TCLBIN=64 OBJECTS="colrowStat.o"' had status 2
Run Code Online (Sandbox Code Playgroud)
但头文件可在 path_to_my_documents/R/win-libraries/3.0/RcppArmadillo/Include 中找到
我认为编译的包含路径没有这个路径。我不知道如何将此文件夹添加到路径中。我非常感谢对这个问题的任何帮助。