You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
326 B
Ruby
17 lines
326 B
Ruby
5 years ago
|
# 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
|