programming-examples/ruby/Algorithms/matrix.rb

17 lines
326 B
Ruby
Raw Normal View History

2019-11-15 12:59:38 +01:00
# Transpose of a matrix in Linear Algebra,
# see examples in test/matrix_test.rb
module Matrix
def self.transpose(matrix)
transposed = []
matrix.each do |row|
row.each_with_index do |el, j|
transposed << [] if transposed[j].nil?
transposed[j] << el
end
end
transposed
end
end