我的问题似乎很基本,但即使在 rpy2 文档中我也找不到答案。我有 *.R 脚本,它接受一个参数作为“file.txt”(我需要不从命令行传递参数)。我想在 python 脚本中调用 R 脚本。我的问题是:如何将参数传递和恢复到 R 脚本?我的解决方案是:假设 R 脚本由此行开始:
df <- read.table(args[1], header=FALSE)
"
here args[1] should be the file which is not passed from the command line
"
....
Run Code Online (Sandbox Code Playgroud)
现在我在我的 python 脚本中编写了一个函数:
from rpy2 import robjects as ro
def run_R(file):
r = ro.r
r.source("myR_script.R")
# how to pass the file argument to
# the R script and how to
# recuperate this argument in the R code?
Run Code Online (Sandbox Code Playgroud) 我有兴趣找到在 Python 中初始化空集的最快方法(我使用的是 3.8)。{}您不能像创建 那样实例化空集dict,因此通常建议使用set()构造函数。前几天我注意到还有另一种方法来实例化空集:您可以将空元组解压()到{...}集合的语法中,如下所示:{*()}。timeit使用in 中的模块对此进行计时ipython会得到以下结果:
%timeit {*()}\n67.7 ns \xc2\xb1 1.68 ns per loop (mean \xc2\xb1 std. dev. of 7 runs, 10000000 loops each)\n\n%timeit set()\n84.5 ns \xc2\xb1 2.57 ns per loop (mean \xc2\xb1 std. dev. of 7 runs, 10000000 loops each)\nRun Code Online (Sandbox Code Playgroud)\n我发现这很奇怪 -set()相对于{*()}. 过去也曾对例如[]vs.list()和{}vs.进行过相同的观察dict()。
%timeit []\n17.8 ns \xc2\xb1 0.791 …Run Code Online (Sandbox Code Playgroud) 当我在 Xilinx Vivado 2016.4 中模拟我的顶级模块时,我收到了奇怪的错误:
ERROR: [VRFC 10-1342] root scope declaration is not allowed in verilog 95/2K mode [<...>/header.vh]
Run Code Online (Sandbox Code Playgroud)
我正在使用指定了 Verilog 2001 的内置Vivado 模拟器。我的header.vh如下所示:
`ifndef _header_vh_
`define _header_vh_
function integer clog2;
input integer value;
begin
value = value - 1;
for (clog2 = 0; value > 0; clog2 = clog2 + 1)
value = value >> 1;
end
endfunction
`endif
Run Code Online (Sandbox Code Playgroud) python ×2
benchmarking ×1
hdl ×1
python-3.x ×1
r ×1
rpy2 ×1
set ×1
verilog ×1
vivado ×1
xilinx ×1