朱莉娅有外部地图功能吗? [英] Is there outer map function in Julia?
问题描述
我正在尝试构造四个向量的所有可能组合(模型中的参数),这将给我一个大的nx4矩阵,然后可以对每个参数(行)进行仿真.在R中,我可以通过使用Mathematica风格的expand.grid
来实现此目的,我可以在vcat
中使用外部乘积,并使用hcat
减少输出.
I am trying to construct all possible combinations of four vectors (parameters in a model) that would give me a big nx4 matrix and I could then run simulation on each set (row) of parameters. In R I would achieve this by using expand.grid
in Mathematica style, I could use something like outer product with vcat
and reduce the output using hcat
.
R或外部映射函数中是否有expand.grid
的函数类似物?
Is there some function analog of expand.grid
from R or outer map function?
玩具示例:
A = [1 2]
B = [3 4]
some magic
output = [1 3, 1 4, 2 3, 2 4]
推荐答案
使用Iterators程序包,看起来可能像这样:
Using the Iterators package, it might look like this:
using Iterators
for p in product([1,2], [3,4])
println(p)
end
,其中您将用算法替换println
.如果要获得所有组合的集合很重要,也可以使用collect
.
where you would replace println
with your algorithm. You can also use collect
if it's important to get the set of all combinations.
这篇关于朱莉娅有外部地图功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!