Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从Ruby中的一组数组创建按列数组_Ruby - Fatal编程技术网

如何从Ruby中的一组数组创建按列数组

如何从Ruby中的一组数组创建按列数组,ruby,Ruby,有没有办法按列组合一组数组 # input arr = [[100, 99, 98], [100, 97, 92], [63, 89, 63], [99, 99, 99], [89, 97, 98]] # output result = [[100, 100, 63, 99, 89], [99, 97, 89, 99, 97], [98, 92, 63, 99, 98]] 换句话说: # input arr = [ [100, 99, 98], [100, 97, 92], [6

有没有办法按列组合一组数组

# input
arr = [[100, 99, 98], [100, 97, 92], [63, 89, 63], [99, 99, 99], [89, 97, 98]]

# output
result = [[100, 100, 63, 99, 89], [99, 97, 89, 99, 97], [98, 92, 63, 99, 98]]
换句话说:

# input
arr = [
  [100, 99, 98],
  [100, 97, 92],
  [63, 89, 63],
  [99, 99, 99],
  [89, 97, 98]
]

# output
result = [
  [100, 100, 63, 99, 89],
  [99, 97, 89, 99, 97],
  [98, 92, 63, 99, 98]
]
是否:

result = arr.transpose
p result #=> [[100, 100, 63, 99, 89], [99, 97, 89, 99, 97], [98, 92, 63, 99, 98]]