ruby 数组行转列/列转行_Ruby_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > Ruby > ruby 数组行转列/列转行

ruby 数组行转列/列转行

 2019/1/8 16:32:27  scholltop  程序员俱乐部  我要评论(0)
  • 摘要:行列转换:用倒置矩阵的方式获取引用require'matrix'arr=[["a1","a2","a3","a4"],["b1","b2","b3","b4"],["c1","c2","c3","c4"]]change_arr=Matrix.columns(ww)change_aee.to_ap#=>[["a1","b2","c3"],["a2","b2","c2"],["a3","b2","c3"],["a4","b4","c4"]]ruby矩阵用法参考http://www.kuqin
  • 标签: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转二维数组:
class="java" name="code">
Array({:a => "a", :b => "b"}) #=> [[:a, "a"], [:b, "b"]]	

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

发表评论
用户名: 匿名