programming-examples/ruby/Algorithms/matrix.rb
2019-11-15 12:59:38 +01:00

17 lines
326 B
Ruby

# 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