APIdock / Ruby
/
method

hstack

ruby latest stable - Class: Matrix
hstack(x, *matrices)
public

Create a matrix by stacking matrices horizontally

x = Matrix [[1, 2], [3, 4]]
y = Matrix [[5, 6], [7, 8]]
Matrix .hstack (x, y) # => Matrix[[1, 2, 5, 6], [3, 4, 7, 8]]
# File lib/matrix.rb, line 234
 def Matrix.hstack(x, *matrices)
 x = CoercionHelper.coerce_to_matrix(x)
 result = x.send(:rows).map(&:dup)
 total_column_count = x.column_count
 matrices.each do |m|
 m = CoercionHelper.coerce_to_matrix(m)
 if m.row_count != x.row_count
 raise ErrDimensionMismatch, "The given matrices must have #{x.row_count} rows, but one has #{m.row_count}"
 end
 result.each_with_index do |row, i|
 row.concat m.send(:rows)[i]
 end
 total_column_count += m.column_count
 end
 new result, total_column_count
 end

AltStyle によって変換されたページ (->オリジナル) /