ruby 数组行转列/列转行

阅读更多
行列转换:用倒置矩阵的方式获取
引用

require 'matrix'
arr = [["a1","a2","a3","a4"],["b1","b2","b3","b4"],["c1","c2","c3","c4"]]
change_arr = Matrix.columns(ww)
change_aee.to_a
p #=>  [["a1","b2","c3"],["a2","b2","c2"],["a3","b2","c3"],["a4","b4","c4"]]


ruby矩阵用法参考
http://www.kuqin.com/rubycndocument/man/addlib/Matrix.html


另外hash转二维数组:
Array({:a => "a", :b => "b"}) #=> [[:a, "a"], [:b, "b"]]	

数组转hash
 [[:a, "a"], [:b, "b"]].to_h  #=> {:a => "a", :b => "b"}

你可能感兴趣的:(ruby,矩阵,数组)