如何转换组合数学的结果
How to convert results from Combinatorics
使用 Julia 1.0.1,我想获得 5 个对象的所有组合的向量,对象是 [1,2],每个数字 3,4,5 和 6
我创建了一个对象 a = [[1,2],3,4,5,6]
并获得了组合。
using Combinatorics
a = [[1,2],3,4,5,6]
anas5 = collect(combinations(a))
不出所料,我正在获得
31-element Array{Array{Any,1},1}:
[[1, 2]]
[3]
[4]
[5]
[6]
[[1, 2], 3]
...
如何转换结果,使包含 [1, 2] 的组合成为向量。
例如,所以上面描述的前几行变成:
[1, 2]
[3]
[4]
[5]
[6]
[1, 2, 3]
...
谢谢
您可以使用 Iterators.flatten
来展平您的 Vector of Vectors。
collect.(Iterators.flatten.(anas5))
使用 Julia 1.0.1,我想获得 5 个对象的所有组合的向量,对象是 [1,2],每个数字 3,4,5 和 6
我创建了一个对象 a = [[1,2],3,4,5,6]
并获得了组合。
using Combinatorics
a = [[1,2],3,4,5,6]
anas5 = collect(combinations(a))
不出所料,我正在获得
31-element Array{Array{Any,1},1}:
[[1, 2]]
[3]
[4]
[5]
[6]
[[1, 2], 3]
...
如何转换结果,使包含 [1, 2] 的组合成为向量。 例如,所以上面描述的前几行变成:
[1, 2]
[3]
[4]
[5]
[6]
[1, 2, 3]
...
谢谢
您可以使用 Iterators.flatten
来展平您的 Vector of Vectors。
collect.(Iterators.flatten.(anas5))