如何并排显示数据(How to display the data side by side)
我正在尝试使用最简单的代码并排显示数据。
问题是当数据丢失时,右侧没有正确
float
。怎么解决?
.pair { background-color: #ccc; } .pair dt { float: left; width: 90px; text-align: right; color: #999; } .pair dd { margin: 0 0 0 100px; }
<dl class="pair"> <dt>Date</dt> <dd>date goes here</dd> <dt>Country</dt> <dd>USA</dd> <dt>Age</dt> <dd></dd> <dt>Name</dt> <dd></dd> <dt>Other</dt> <dd>other info goes here</dd> </dl>
I'm trying to display the data side by side using the most simple code possible.
The problem is when the data is missing, the right side doesn't
float
correctly.How to fix it?
.pair { background-color: #ccc; } .pair dt { float: left; width: 90px; text-align: right; color: #999; } .pair dd { margin: 0 0 0 100px; }
<dl class="pair"> <dt>Date</dt> <dd>date goes here</dd> <dt>Country</dt> <dd>USA</dd> <dt>Age</dt> <dd></dd> <dt>Name</dt> <dd></dd> <dt>Other</dt> <dd>other info goes here</dd> </dl>
原文:
满意答案
使用armadillo的
.memptr()
类成员函数,我们可以提取内存指针。 从这里,我们可以使用Eigen的Map<T>()
构造函数来创建一个特征矩阵。现在,我们可以使用
.data()
成员函数从Eigen矩阵中提取一个指向Eigen内存结构的点。 然后,使用arma::mat
的高级构造函数选项,我们可以创建一个armadillo 矩阵 。例如:
#include <RcppArmadillo.h> #include <RcppEigen.h> // [[Rcpp::depends(RcppEigen)]] // [[Rcpp::depends(RcppArmadillo)]] // [[Rcpp::export]] Eigen::MatrixXd example_cast_eigen(arma::mat arma_A) { Eigen::MatrixXd eigen_B = Eigen::Map<Eigen::MatrixXd>(arma_A.memptr(), arma_A.n_rows, arma_A.n_cols); return eigen_B; } // [[Rcpp::export]] arma::mat example_cast_arma(Eigen::MatrixXd eigen_A) { arma::mat arma_B = arma::mat(eigen_A.data(), eigen_A.rows(), eigen_A.cols(), false, false); return arma_B; } /***R (x = matrix(1:4, ncol = 2)) example_cast_eigen(x) example_cast_arma(x) */
结果:
(x = matrix(1:4, ncol = 2)) # [,1] [,2] # [1,] 1 3 # [2,] 2 4 example_cast_eigen(x) # [,1] [,2] # [1,] 1 3 # [2,] 2 4 example_cast_arma(x) # [,1] [,2] # [1,] 1 3 # [2,] 2 4
快速说一句:如果您使用的是Eigen的映射函数,那么您应该自动对Armadillo矩阵进行更改(反之亦然),例如
#include <RcppArmadillo.h> #include <RcppEigen.h> // [[Rcpp::depends(RcppEigen)]] // [[Rcpp::depends(RcppArmadillo)]] // [[Rcpp::export]] void map_update(Eigen::MatrixXd eigen_A) { Rcpp::Rcout << "Eigen Matrix on Entry: " << std::endl << eigen_A << std::endl; arma::mat arma_B = arma::mat(eigen_A.data(), eigen_A.rows(), eigen_A.cols(), false, false); arma_B(0, 0) = 10; arma_B(1, 1) = 20; Rcpp::Rcout << "Armadill Matrix after modification: " << std::endl << arma_B << std::endl; Rcpp::Rcout << "Eigen Matrix after modification: " << std::endl << eigen_A << std::endl; }
跑:
map_update(x)
输出:
Eigen Matrix on Entry: 1 3 2 4 Armadill Matrix after modification: 10.0000 3.0000 2.0000 20.0000 Eigen Matrix after modification: 10 3 2 20
Using armadillo's
.memptr()
class member function, we are able to extract the memory pointer. From here, we can use Eigen'sMap<T>()
constructor to create an Eigen matrix.Now, we can go from the Eigen matrix using the
.data()
member function to extract a point to Eigen's memory structure. Then, using the advanced constructor options ofarma::mat
we can create an armadillo matrix.For example:
#include <RcppArmadillo.h> #include <RcppEigen.h> // [[Rcpp::depends(RcppEigen)]] // [[Rcpp::depends(RcppArmadillo)]] // [[Rcpp::export]] Eigen::MatrixXd example_cast_eigen(arma::mat arma_A) { Eigen::MatrixXd eigen_B = Eigen::Map<Eigen::MatrixXd>(arma_A.memptr(), arma_A.n_rows, arma_A.n_cols); return eigen_B; } // [[Rcpp::export]] arma::mat example_cast_arma(Eigen::MatrixXd eigen_A) { arma::mat arma_B = arma::mat(eigen_A.data(), eigen_A.rows(), eigen_A.cols(), false, false); return arma_B; } /***R (x = matrix(1:4, ncol = 2)) example_cast_eigen(x) example_cast_arma(x) */
Results:
(x = matrix(1:4, ncol = 2)) # [,1] [,2] # [1,] 1 3 # [2,] 2 4 example_cast_eigen(x) # [,1] [,2] # [1,] 1 3 # [2,] 2 4 example_cast_arma(x) # [,1] [,2] # [1,] 1 3 # [2,] 2 4
One quick remark: If you are using Eigen's Mapping function, then you should automatically have the change in the Armadillo matrix (and vice versa), e.g.
#include <RcppArmadillo.h> #include <RcppEigen.h> // [[Rcpp::depends(RcppEigen)]] // [[Rcpp::depends(RcppArmadillo)]] // [[Rcpp::export]] void map_update(Eigen::MatrixXd eigen_A) { Rcpp::Rcout << "Eigen Matrix on Entry: " << std::endl << eigen_A << std::endl; arma::mat arma_B = arma::mat(eigen_A.data(), eigen_A.rows(), eigen_A.cols(), false, false); arma_B(0, 0) = 10; arma_B(1, 1) = 20; Rcpp::Rcout << "Armadill Matrix after modification: " << std::endl << arma_B << std::endl; Rcpp::Rcout << "Eigen Matrix after modification: " << std::endl << eigen_A << std::endl; }
Run:
map_update(x)
Output:
Eigen Matrix on Entry: 1 3 2 4 Armadill Matrix after modification: 10.0000 3.0000 2.0000 20.0000 Eigen Matrix after modification: 10 3 2 20
相关问答
更多将NSString转换为NSData,反之亦然(Converting NSString to NSData and vice versa)
如何转换Eigen :: Affine3f至Eigen :: Matrix4f(How to convert from Eigen::Affine3f to Eigen::Matrix4f)
如何使用Eigen :: Matrix作为参考(How to use Eigen::Matrix by reference)
Eigen C ++ Sparse Matrix元素乘积和除法(Eigen C++ Sparse Matrix elementwise product and divide)
犰狳整数特征分解(Armadillo integer eigen decomposition)
对于R中的对角矩阵,用1代替0,反之亦然(replace 0's with 1's and vice versa for a diagonal matrix in R)
将int []转换为short [],反之亦然(Converting int[] to short[] and vice versa)
如何将邻接矩阵转换为发生率矩阵,反之亦然?(How do you transform Adjacency matrices to Incidence matrices and vice-versa?)
犰狳vs Eigen3时间差异(Armadillo vs Eigen3 Timing Difference)
将犰狳矩阵转换为特征MatriXd,反之亦然(Converting an Armadillo Matrix to an Eigen MatriXd and vice versa)
相关文章
更多Riak, haproxy, and client side applications
The Log: What every software engineer should know about real-time data's unifying abstraction
关于 style="display:none" 得问题
Becoming a data scientist
data-config
(二)solr data import
《Big Data Glossary》笔记
Spring Data Solr教程(翻译)
TMF大数据分析指南 Unleashing Business Value in Big Data(一)
自己封装的一个Solr Data Import Request Handler Scheduler
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!