a = [1, 2, 3]
b = [4, 5, 6]
How would I combine the two arrays in a 2D array?:
如何在二维数组中组合这两个数组?
[[1, 4], [2, 5], [3, 6]]
2 个解决方案
#2
10
While zip
is obviously the most straightforward answer, this also works:
虽然zip显然是最直接的答案,但它也适用:
[a, b].transpose
=> [[1, 4], [2, 5], [3, 6]]
#1
#2
10
While zip
is obviously the most straightforward answer, this also works:
虽然zip显然是最直接的答案,但它也适用:
[a, b].transpose
=> [[1, 4], [2, 5], [3, 6]]