Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
a = [1, 2, 3] b = [4, 5, 6]
我如何将两个数组组合成一个二维数组?:
[[1, 4], [2, 5], [3, 6]]
试试数组#zip
a.zip(b) => [[1,4],[2,5],[3,6]]
虽然zip显然是最直接的答案,但这也有效:
zip
[a, b].transpose => [[1, 4], [2, 5], [3, 6]]