- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含两组的数据集:红色和绿色,我想比较比率之间的差异,但它们必须首先对齐。
原始文件(前几行 200,000 个条目)
A B C D
Red Ratio Green Ratio
1 0.35 1 0.21
2 0.45 2 0.235
3 0.45 3 0.154
4 0.235 4 0.156
6 0.156 5 0.146
7 0.668 6 0.154
8 0.44 7 0.148
9 0.446 8 0.148
10 0.354 9 0.199
11 0.154 10 0.143
12 0.49 12 0.148
使用代码后,值会对齐,“额外”会被删除,列会向上移动。
A B C D
Red Ratio Green Ratio
1 0.35 1 0.21
2 0.45 2 0.235
3 0.45 3 0.154
4 0.235 4 0.156
6 0.156 6 0.154
7 0.668 7 0.148
8 0.44 8 0.148
9 0.446 9 0.199
10 0.354 10 0.143
12 0.49 12 0.148
15 0.146 15 0.87
17 0.113 17 0.113
19 0.44 19 0.448
这是我到目前为止的代码:我正在计算 A 和 C 之间的差异来检查它们是否为 0,如果不是则调整它们。
#include <stdio.h>
int deletemove(char column, int row)
{
// This script would delete the positions mentioned in the arguments, and shift the other values up.
}
int main(void)
{
//Opening input file for read/write
FILE *input;
input=fopen("/full/path/file.xlsx", "r");
if (input == NULL) {printf("error opening input file\n");}
//Store the values from file into an array
int colA[1024];
int colC[1024];
// read contents of columns A and C and store in an array
int ai;
for(ai=1; ai<1024; ai++)
{ fseek(input,ai,SEEK_SET);
colA[ai]=fgetc(input);
}
int ci;
for(ci=1; ci<1024; ci++)
{ fseek(input,ci,SEEK_SET);
colC[ci]=fgetc(input);
}
//Take difference between value of Column A and C to check if they are identical.
int j;
char A,B;
for (j = 1; j < 1024; j++)
{
int check = colA[j] - colC[j]; // check difference between two values in a column
if (check > 0)
deletemove(A,j); //delete values from column C and D
else if (check < 0)
deletemove(B,j); // delete values from column A and B
}
fclose(input); // close files
}
我需要帮助实现删除行/列函数并读取数组中的值。
另外,在数组中存储 200,000 个值是可行的方法吗?
谢谢。
最佳答案
is storing 200,000 values in an array a feasible method?
是的,只要您不将这些数组放入堆栈即可。在函数内声明变量会将变量放入堆栈(1)。现代(2016 年)桌面通常将堆栈大小限制为几兆字节,而主内存为几千兆字节。
所以最好将大数组放入主存中。这可以通过多种方式完成:
static
关键字声明数组malloc
来分配数组(您也可以使用链表。链表的优点是它可以根据需要增长;您不需要提前知道空间要求。)
在您的情况下,我会将比率存储在数组中由红色/绿色值给出的索引处。假设比率始终为正数,我将使用 -1.0
初始化数组中的所有条目。然后,当您读取文件时,将比率存储在两个数组中的正确位置。例如,当您阅读该行
6 0.156 5 0.146
将 0.156
存储在红色数组中的索引 6
处,并将 0.146
存储在绿色数组中的索引 5
处大批。
从文件中读取所有值后,您可以简单地扫描两个数组,并打印两个数组都具有非负值的值。
(1) 忽略没有正常堆栈的奇怪系统(例如小型嵌入式系统)。
关于c - 在 C 中对齐数据集列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39397567/
我希望能够像在 jsFiddle 中那样将元素列表对齐到右侧的复选框。这是如何做到这一点的最佳实践?传统上我从来没有 float 过相互嵌套的元素,所以我想确定这是否是解决此问题的正确方法。 代码(h
指令.align n是什么意思在数组中做什么? 更具体地说,假设我有以下部分代码: array: .align 2 .space 800 它的重要性是什么,为什么不跳过它并使用
基本上我正在寻找一种强制特定相对对齐的方法 即我想保证其他一些值(value) m s.t m > n alignment_of(foo) % 2^m == 2^n IE: .align 2^m; .
在我的代码中,我必须考虑一个数组数组,其中内部数组具有固定维度。为了使用 STL 算法,将数据实际存储为数组的数组很有用,但我还需要将该数据传递给 C 库,该库采用扁平化的 C 样式数组。 如果能够以
横向上,我想显示两个位图,并在它们之间显示一个标签字段。 代码看起来很简单,但所有字段都添加在屏幕左侧。 HorizontalFieldManager hfm = new HorizontalFiel
我想绘制一个变量名称及其符号。因为某些变量的名称很长,所以我试图将换行符与轴标签混合使用。这会导致对齐中发生有趣的事情: par(mar=c(1,12,1,1)) plot( y=1:6, 1:6,
使用这个脚本 df <- data.frame(x = 1:5, y = 1:5, color = letters[1:5]) ggplot(df, aes(x, y, fill = color))
我有一个带有标量字段的结构,比如妈妈,我想在屏幕上对齐的列中显示结构的值,可能还有一些标题。这是一个最小的工作示例: mom.a = 1; mom.b = 2; mom.veryLongName =
在 iOS6 中,我使用自动布局。 我有 2 个以编程方式创建的 View v1 和 v2。 v2 作为 subview 添加到 v1 v1 的约束已通过编程方式创建(此处未显示)。 我希望 v1 和
概述 浏览时operator new, operator new[] - cppreference.com ,似乎我们有许多选项来分配具有特定对齐要求的对象数组。但是,没有指定如何使用它们,而且我似乎
Widget _createProfileContainer() { return new Container( height: 64.0, child: ne
我正在使用 Bootstrap 和语义 UI 的组合来设计和对齐我的网页。目前,我在将页面 api map 和博客文章在整个页面上对齐时遇到问题,而不是像图像所示 那样堆叠在一起。 这是我的底层代码,
所以我已经添加了标签和所有内容,但我仍然在格式化和对齐所有内容时遇到问题。计算按钮显然应该居中。我知道使用 gridbag 将框架分割成坐标系,当一列大于其他列时,它会调整其他列并将其抛弃(对吗?)。
我必须将程序上的按钮对齐到中间,我运行的当前代码但显示的按钮与程序一样大,我想要一个特定大小的中心按钮,这是我尝试过的 /** * Created by Timk9 on 11/04/2016.
我正在尝试将 VIM 作为我的 ruby/rails 编辑器。太胖了,我对它的功能印象深刻 并且我能够安装以下插件以提供更好的 IDE 体验 自动配对 Better-snipmate-snippe
在结构内对齐成员的最佳或常规方法是什么?添加虚拟数组是最佳解决方案吗? 我有一个 double 的结构和 double 的三倍是吗? struct particle{ double mass;
我正在尝试对齐我的输出,但由于某种原因我无法做到我多么想要它,这真的很令人沮丧。标题不会正确对齐。我不知道我是否正确使用了 setw()。 #include using std::cout; usi
我正在开发一个 android 应用程序,其相对布局如下所示。 这是应用程序在屏幕上的显示方式的 imgur 链接:http://imgur.com/c4rNJ .我希望“Text 1”出现在“a l
我不确定为什么我不能在下面的代码中调整按钮的位置。我有几行设置了边界,但我一定遗漏了一些东西。 public DayGUI() { mainFrame = new JF
我有一个 html 页面,我想在页面底部对齐一个 iframe,使 iframe 占据所有宽度,我无法在底部对齐 iframe。请找到底部的 iframe 标签页面。 The rest of th
我是一名优秀的程序员,十分优秀!