作为一个练习来了解std::async我写了一个小程序,计算一个大的总和vector<int>,分布了很多线程.
我的代码如下
#include <iostream>
#include <vector>
#include <future>
#include <chrono>
typedef unsigned long long int myint;
// Calculate sum of part of the elements in a vector
myint partialSum(const std::vector<myint>& v, int start, int end)
{
myint sum(0);
for(int i=start; i<=end; ++i)
{
sum += v[i];
}
return sum;
}
int main()
{
const int nThreads = 100;
const int sizePerThread = 100000;
const int vectorSize = nThreads * sizePerThread;
std::vector<myint> v(vectorSize);
std::vector<std::future<myint>> partial(nThreads);
myint tot …Run Code Online (Sandbox Code Playgroud) 我经常使用wxtGnuplot 的终端进行一些快速的数据检查.我喜欢交互性,这样我就可以轻松获得控制和缩放/移动等等.
假设我必须遵循脚本
set terminal wxt 0 persist
plot x
set terminal wxt 1 persist
plot x**2
Run Code Online (Sandbox Code Playgroud)
现在,在窗口1上,我有了交互式控件.但是,在窗口0上,此交互式控件将丢失.
我的问题是:如何在窗口0上获得交互式控制?
我在用gnuplot 4.6.2.我已经看到gnuplot多个图形不是交互式的,但关于x11终端的问题,答案包括打开多个实例gnuplot,这对我来说似乎没有必要.
我正在使用Matlab R2013b.我正在使用GUI,在分屏中使用Command Windows和Editor.在Matlab首选项>编辑器/调试器>编辑器中.可以选择设置自定义编辑器而不是Matlab编辑器.我将它设置为我的本地编辑器/usr/bin/vim,但后来我再也无法打开文件了.是否有可能vim在分屏模式下使用编辑器?
我知道!vim file.m,但这不是我正在寻找的解决方案,因为这只能在-nodisplay模式中令人满意.我宁愿保持分屏模式.
假设我有以下脚本来制作一种轮廓图。
set colorbox horizontal user origin 0.1, 0.9 size 0.8, 0.05
set pm3d map
splot x*y
Run Code Online (Sandbox Code Playgroud)
这给出了以下结果。

现在,我想要实现的是,刻度标签会自动结束在颜色框的相反位置。我怎样才能做到这一点?
我试过:
set cbtics mirror,但这不会改变任何事情。set cbtics offset 0,3。这原则上有效,但我每次都必须调整它。我的gnuplot版本是4.6.2
我尝试使用awk命令计算文件中第4个字段大于第一个字段的行数我想出了这个命令:
awk '$4>$1 {print}' sampleFile | wc -l
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来找到数字而不是使用 wc -l
我有一个数据文件,可能是一行或多行.我用它读了numpy.loadtxt.这具有使我的单行数据成为标量的功能.这是有问题的,因为我想在读入后使用循环.请参阅下面的示例
$ cat file1
1
$ cat file2
1
2
$ python --version
Python 2.7.6
$ python
$ python temp.py
1.0
2.0
Traceback (most recent call last):
File "temp.py", line 9, in <module>
for x in data1:
TypeError: iteration over a 0-d array
Run Code Online (Sandbox Code Playgroud)
码
import numpy
data1=numpy.loadtxt ( 'file1', unpack=True )
data2=numpy.loadtxt ( 'file2', unpack=True )
for x in data2:
print x
for x in data1:
print x
Run Code Online (Sandbox Code Playgroud)
我也尝试了相关问题的解决方案:numpy loadtxt单行/行作为列表但我不能让它工作
我补充道
data1 = data1 if usi.shape …Run Code Online (Sandbox Code Playgroud) 我想做的是类似的事情(这是伪代码):
for txt in $(some fancy command ./*.txt); do
some command here $txt
Run Code Online (Sandbox Code Playgroud) 我简化了我的问题.
此代码仅将list.txt文件的最后一个文本行后跟一个CR/LF写入newlist.txt文件.怎么会.它将所有条目打印到屏幕上的一行,但只将最后一行写入文件.
这是我关于这个主题的第一篇文章的关键,但我正在努力简化这个问题
f = open("list.txt","r")
for line in f:
print(line)
output = open("newlist.txt",'w', newline="\r\n")
output.write(line)
f.close()
Run Code Online (Sandbox Code Playgroud) 假设我的 gnuplot (4.6.2) 版本有以下最小工作示例。
set terminal epslatex size 6cm, 4cm font "" 8 standalone
set output "test.tex"
set xrange [0:10]
set yrange [0:10]
set label "$\\alpha=1\,b=0.1$" at 2,8
plot x
Run Code Online (Sandbox Code Playgroud)
这给了我以下输出:

我现在想要的是将我的参数 alpha 和 b 放在彼此下方,在等号处最佳对齐。
我试过类似的东西
set label "\\begin{eqnarray}\\alpha=1 \\\\ b=0.1\\end{eqnarray}" at 2,8
Run Code Online (Sandbox Code Playgroud)
这不会在 gnuplot 中给我错误,但是在编译时它失败了,错误类似于
! Missing \endgroup inserted.
<inserted text>
\endgroup
l.153 \gplbacktext
Run Code Online (Sandbox Code Playgroud)
这并没有真正帮助我进一步。
关于如何解决这个问题的任何建议?