Module | JBLAS::MatrixConvertMixin |
In: |
lib/jblas/mixin_convert.rb
|
Mixin for conversion options.
Collected in MatrixMixin.
# File lib/jblas/mixin_convert.rb, line 78 def columns_to_a (0...columns).map do |j| column(j).to_a end end
Return an a representation of this object.
# File lib/jblas/mixin_convert.rb, line 68 def inspect s = "<#{self.class} of size #{rows} #{columns}: #{to_s}>" end
Convert the matrix to an array.
If the matrix
# File lib/jblas/mixin_convert.rb, line 87 def to_ary to_a end
Convert this matrix to a string.
This methods takes a few extra arguments to control how the result looks like.
fmt is a format as used by sprintf, coljoin is the string used to join column, rowjoin is what is used to join rows. For example,
x.to_s('%.1f', ' ', "\n")
Returns a matrix where columns are separated by spaces, rows by newlines and each element is shown with one digit after the comma.
# File lib/jblas/mixin_convert.rb, line 52 def to_s(fmt=nil, coljoin=', ', rowjoin='; ') if fmt x = rows_to_a '[' + x.map do |r| if Enumerable === r r.map {|e| sprintf(fmt, e)}.join(coljoin) else sprintf(fmt, r) end end.join(rowjoin) + ']' else toString end end