请考虑以下声明:
vector<vector<int> > v2d;
vector<vector<vector<string>> > v3d;
Run Code Online (Sandbox Code Playgroud)
如何在后续代码中找出向量的"维度"?例如,v2d为2,v3d为3?
有没有办法调整std :: stod()以增加(字符串到双)转换中的小数位数并强制它使用美国语言环境?
我有一个Qt应用程序,可以在控制台或gui模式下运行:
if (opt->getFlag( 'c' ) || opt->getFlag( "console" ) ){
ThreadManager modelMainThread;
modelMainThread.runFromConsole(inputFileName,scenarioName);
}
else {
QApplication app(argc, argv);
MainWindow mainWin;
mainWin.show();
return app.exec();
}
Run Code Online (Sandbox Code Playgroud)
在这个应用程序中,我有一个包含新C++ 11 stod的字符串到double方法:
double s2d ( const string &string_h) const {
try {
return stod(string_h);
} catch (...) {
if (string_h == "") return 0;
else {
cout << "error!" << endl;
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,在控制台模式下,字符串到双转换需要一个带点作为十进制分隔符的字符串,在gui模式下它需要一个带逗号的字符串.此外,正如我以前使用istringstream:
istringstream totalSString( valueAsString );
totalSString >> valueAsDouble;
Run Code Online (Sandbox Code Playgroud)
我注意到stod会将生成的double缩减为只有3位十进制数,远小于istringstream.
那么有没有办法增加十进制数字的数量并强制std :: stod使用美国语言环境进行转换?
谢谢 :-)
编辑 …
编辑:我不是问如何用给定的变量来解决方程式(如在这个假定的重复问题中),而是如何用问题中指定的另一个表示表达式.我认为这是一个具有误导性标题的"重复"问题.
我是SymPy的新手.我有一个表达,一旦表达为另一个表达式,应该变得非常好.问题是我不知道如何"强迫"用另一个表达原始表达.
这是一个基本的例子:
import sympy as sp
sp.init_printing(use_unicode=True)
a,b,c = sp.symbols('a b c')
A = a+b+c
B = a+c
C = A.subs(a+c,B) # Expected/wanted: C = B+b
C
Run Code Online (Sandbox Code Playgroud)
A.rewrite(B)
Run Code Online (Sandbox Code Playgroud)
A和B可能是相当复杂的表达.作为参考,这是我的实际情况:
import sympy as sp
sp.init_printing(use_unicode=True)
t, w, r = sp.symbols('t w r')
S = sp.Function('S')(t)
V = (S-w*(1+r)**t)/(((1+r)**t)-1)
V
Run Code Online (Sandbox Code Playgroud)
St = -(r + 1)**t*(w - S)*sp.log(r + 1)/((r + 1)**t - 1)
St
Run Code Online (Sandbox Code Playgroud)
一旦我按照V语言编写St,我应该能够简化以获得公正
St = rS(t)+ rV
但我无法在SymPy中做到这一点.
我正在尝试将两条垂直线添加到绘图中,并在 x 轴上带有相应的刻度和标签,以突出显示重要点。
我找到了两种方法(后面的 A 和 B),但在第一种方法中,新的刻度/标签替换而不是附加旧的,而在第二种方法中,标签打印在某种不一致的位置(取决于范围)和无法将它们带到我想要的地方:
using Plots, StatPlots, DataFrames
pyplot()
df = DataFrame(a = 1:10, b = 10*rand(10), c = 10 * rand(10))
f = Plots.font("DejaVu Sans", 10)
@df df plot(:a, [:b :c], label=["serie a" "serie b"], xtickfont=f, ytickfont=f, legendfont=f, guidefont=f, titlefont=f)
Run Code Online (Sandbox Code Playgroud)
A:
plot!([5,7], seriestype="vline", xticks = ([5,7],["\$\\bar \\delta \$","\$\\bar \\gamma \$"]), label="")
Run Code Online (Sandbox Code Playgroud)
乙:
plot!([5], seriestype="vline", label="")
annotate!(5, 0, text("\$ \\bar \\delta \$",f, :bottom, :left))
plot!([7], seriestype="vline", label="")
annotate!(7, 0, text("\$\\bar \\gamma \$",f, :top)
Run Code Online (Sandbox Code Playgroud)
0.7 警告使用revise.jl,但在其文档中我找不到一个命令只说“全部清理”。
是的,我可以确定只是重新启动 Julia,但是在 IDE 中点击几下就可以了,而有时我只想清除以前定义的所有变量/模块。
在pandas数据框中,如何有条件地将列的值填充到列表中的另一列中的值?
这非常类似于这个问题,但是当我申请时:
df['type'] = np.where(df['food'] in ['apple', 'banana', 'kiwi'], 'fruit', 'oth. food')
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Run Code Online (Sandbox Code Playgroud)
我想in运算符没有被覆盖以使用向量..
在快速解释性工作中,IndexedTables似乎比DataFrames处理单个元素(例如选择或“更新”)要快得多,但DataFrames具有更好的功能生态系统,例如绘图、导出......
因此,在工作流的某个时刻,我想将 IndexedTable 转换为 DataFrame,例如
using DataFrames, IndexedTables, IndexedTables.Table
tn = Table(
Columns(
param = String["price","price","price","price","waterContent","waterContent"],
item = String["banana","banana","apple","apple","banana", "apple"],
region = Union{String,DataArrays.NAtype}["FR","UK","FR","UK",NA,NA]
),
Columns(
value2000 = Float64[2.8,2.7,1.1,0.8,0.2,0.7],
value2010 = Float64[3.2,2.9,1.2,0.8,0.2,0.8],
)
)
Run Code Online (Sandbox Code Playgroud)
到 >>
df_tn = DataFrame(
param = String["price","price","price","price","waterContent","waterContent"],
item = String["banana","banana","apple","apple","banana", "apple"],
region = Union{String,DataArrays.NAtype}["FR","UK","FR","UK",NA,NA],
value2000 = Float64[2.8,2.7,1.1,0.8,0.2,0.7],
value2010 = Float64[3.2,2.9,1.2,0.8,0.2,0.8],
)
Run Code Online (Sandbox Code Playgroud)
或者
t = Table(
Columns(
String["price","price","price","price","waterContent","waterContent"],
String["banana","banana","apple","apple","banana", "apple"],
Union{String,DataArrays.NAtype}["FR","UK","FR","UK",NA,NA]
),
Columns(
Float64[2.8,2.7,1.1,0.8,0.2,0.7],
Float64[3.2,2.9,1.2,0.8,0.2,0.8],
)
)
Run Code Online (Sandbox Code Playgroud)
到 >>
df_t = …Run Code Online (Sandbox Code Playgroud) 我发现所有用于说明Julia <0.6中类型不稳定性的性能瓶颈的示例在Julia> = 0.7中均不再有效,因为它们通常使用两种或几种可能的类型,但是现在编译器在处理Union{T1,T2,..}类型方面也很有效,因此与相应类型稳定版本的差异消失了。
您能否说明一个简单的类型不稳定函数的示例,当该类型变为类型稳定函数时,该函数仍具有较大的性能改进?
I would like to understand, from the user point of view, the differences in multithreading programming models between Julia >= 1.3 and Python 3.
Is there one that is more efficient than the other (in the sense that rising the thread numbers reduces more the computational time) ? In which situations (e.g. one model may have an edge, but only on computational or memory intensive tasks) ?
一个比另一个更实用/提供更高级别的功能吗?
一个比另一个更灵活(例如,它可以应用于更广泛的案例集)?
#include <iostream>
using namespace std;
int main() {
int steps=1000000000;
float s = 0;
for (int i=1;i<(steps+1);i++){
s += (i/2.0) ;
}
cout << s << endl;
}
Run Code Online (Sandbox Code Playgroud)
声明s为float:9.0072e + 15
声明s为double:2.5e + 17(与Julia中实现的结果相同)
据我所知,它double具有双精度float,但float仍应处理高达10 ^ 38的数字.
我确实读过类似的主题,其结果不尽相同,但在那种情况下,差异非常小,这里差异是25倍.
我还补充说,使用long double而不是给我相同的结果double.如果事情是精确的,我会期望有一些不同的东西.