如何并排显示数据(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>


原文:
2022-03-15 13:03

满意答案

使用armadillo.memptr()类成员函数,我们可以提取内存指针。 从这里,我们可以使用EigenMap<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's Map<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 of arma::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)

NSString到NSData : NSString* str= @"teststring"; NSData* data=[str dataUsingEncoding:NSUTF8StringEncoding]; NSData到NSString : NSString* newStr = [[NSString alloc] initWithData:theData encoding:NSUTF8StringEncod...

如何转换Eigen :: Affine3f至Eigen :: Matrix4f(How to convert from Eigen::Affine3f to Eigen::Matrix4f)

是的,在内部,Affine3f存储了MatrixXf,因此您可以: Eigen::Affine3f A; Eigen::Matrix4f M; M = A.matrix(); A = M; // assume that M.row(3) == [0 0 0 1] Yes, internally an Affine3f stores a MatrixXf, so you can do: Eigen::Affine3f A; Eigen::Matrix4f M; M = ...

如何使用Eigen :: Matrix作为参考(How to use Eigen::Matrix by reference)

Si! 特征矩阵可以作为参考传递。 这是一个工作示例: #include <iostream> #include <Eigen/Dense> void calc(Eigen::MatrixXf& mat) { mat = Eigen::MatrixXf::Constant(mat.rows(), mat.cols(), 1.0); } int main() { Eigen::MatrixXf Mat; Mat = Eigen::Matrix4f::Identity();...

Eigen C ++ Sparse Matrix元素乘积和除法(Eigen C++ Sparse Matrix elementwise product and divide)

这是不受支持的,因为严格地说,你会为任何显式零计算0/0。 如果矩阵处于压缩模式,您可以解决方法,以确保调用: beta.makeCompressed(); 然后将非零值映射为密集数组: Map<ArrayXd> a(beta.valuePtr(), beta.nonZeros(); (a / a.abs()).sum; This is not supported because rigorously you would compute 0/0 for any explicit zeros. ...

犰狳整数特征分解(Armadillo integer eigen decomposition)

首先使用conv_to函数将整数矩阵转换为双矩阵。 例如, imat A = ...; mat B = conv_to<mat>::from(A); imat A = ...; mat B = conv_to<mat>::from(A); 。 然后,您可以对转换后的矩阵进行特征分解。 First convert the integer matrix to a double matrix using the conv_to function. For example, imat A = ...; m...

对于R中的对角矩阵,用1代替0,反之亦然(replace 0's with 1's and vice versa for a diagonal matrix in R)

如果您的矩阵无法使用,并且您想要将所有1都翻转为0 ... mat <- 1-mat If your matrix is mat and you want to flip all 1s as 0s... mat <- 1-mat

将int []转换为short [],反之亦然(Converting int[] to short[] and vice versa)

对于您可能希望尽可能快的事情,您可能需要考虑编写自己的循环以将short[]数组复制到新的int[]数组中,例如: public static int[] Convert(short[] input) { int[] result = new int[input.Length]; for (int i = 0; i < input.Length; ++i) result[i] = input[i]; return result; } 这是你如何转换回来...

如何将邻接矩阵转换为发生率矩阵,反之亦然?(How do you transform Adjacency matrices to Incidence matrices and vice-versa?)

您可以通过查看顶点之间的每个可能的连接将邻接矩阵转换为关联矩阵,并且只要确实存在连接,就为您的关联矩阵添加边。 但是,要小心只查看每个顶点组合一次。 反过来说,你可以简单地看一下每条边。 入射矩阵为每条边指定了它连接的两个顶点。 您无法重新创建的一种情况是,当多个边缘连接相同的两个顶点时。 这里有一些源代码来说明上面的解释( 见工作 ): #include <vector> #include <cassert> #include <iostream> typedef std::vector<bo...

犰狳vs Eigen3时间差异(Armadillo vs Eigen3 Timing Difference)

“这很复杂。” 我们通过附加软件包RcppArmadillo和RcppEigen为Armadillo和Eigen提供绑定,因此比较和赛马问题出现了很多。 而且我认为没有一个明确的答案。 为了使事情“更糟”,犰狳通常指你安装的任何LAPACK / BLAS,因此你可以使用多核并行,而Eigen倾向于选择自己的例程。 在准备我的Rcpp书籍时,我做了一些时间安排,发现了一些反直觉的结果。 在一天结束时,您可能需要简单描述您的问题。 "It's complicated." We offer bindin...

将犰狳矩阵转换为特征MatriXd,反之亦然(Converting an Armadillo Matrix to an Eigen MatriXd and vice versa)

使用armadillo的.memptr()类成员函数,我们可以提取内存指针。 从这里,我们可以使用Eigen的Map<T>()构造函数来创建一个特征矩阵。 现在,我们可以使用.data()成员函数从Eigen矩阵中提取一个指向Eigen内存结构的点。 然后,使用arma::mat的高级构造函数选项,我们可以创建一个armadillo 矩阵 。 例如: #include <RcppArmadillo.h> #include <RcppEigen.h> // [[Rcpp::depends(Rcpp...

相关文章

更多

Riak, haproxy, and client side applications

转载:http://blog.dloh.org/Riak,-haproxy,-and-client-s ...

关于 style="display:none" 得问题

display:none 可以隐藏 该div. 要显示的时候,用block 或者 inline. ...

Becoming a data scientist

Data Week: Becoming a data scientist Data Pointed, ...

data-config

Data-config为solr的data-import处理器配置数据来源。 依次按照如下树状结构: ...

(二)solr data import

solr 的 data import 导入 mysql数据 (1)、编辑 example/solr/c ...

《Big Data Glossary》笔记

清明假期翻以前的笔记发现有一些NoSQL相关的内容,比较零散,是之前读《Big Data Glossa ...

Spring Data Solr教程(翻译)

大多数应用都必须具有某种搜索功能,问题是搜索功能往往是巨大的资源消耗并且它们由于沉重的数据库加载而拖垮 ...

TMF大数据分析指南 Unleashing Business Value in Big Data(一)

大数据分析指南 TMF Frameworx最佳实践 Unleashing Business Value ...

自己封装的一个Solr Data Import Request Handler Scheduler

经过将近一天的努力,终于搞定了Solr的Data Import Request HandlerSche ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本