class NMatrix
Public Instance Methods
column(col_number, get_by = :copy)
click to toggle source
# File lib/nmatrix/rowcol.rb, line 27 def column(col_number, get_by = :copy) if dim > 1 && col_numbers = get_row_or_col_index_array(col_number) out = NMatrix.new [rows, col_numbers.length], default_value, dtype: dtype, stype: stype col_numbers.each_with_index do |colnum, i| out[0..-1, i] = self[0..-1, colnum] end out else internal_column(col_number, get_by) end end
Also aliased as: internal_column, col
row(row_number, get_by = :copy)
click to toggle source
# File lib/nmatrix/rowcol.rb, line 7 def row(row_number, get_by = :copy) if row_numbers = get_row_or_col_index_array(row_number) out = NMatrix.new [row_numbers.length, cols].compact, default_value, dtype: dtype, stype: stype row_numbers.each_with_index do |rownum, i| if dim > 1 out[i, 0..-1] = self[rownum, 0..-1] else out[i] = self[rownum] end end out else internal_row(row_number, get_by) end end
Also aliased as: internal_row
Private Instance Methods
booleans_to_indexes(row_numbers)
click to toggle source
# File lib/nmatrix/rowcol.rb, line 52 def booleans_to_indexes row_numbers row_numbers.map.with_index {|v, i| i if v}.compact end
get_row_or_col_index_array(arg)
click to toggle source
# File lib/nmatrix/rowcol.rb, line 45 def get_row_or_col_index_array arg return unless arg.is_a?(Array) || arg.is_a?(NMatrix) out = arg.to_a.flatten out = booleans_to_indexes(out) unless out.first.is_a?(Integer) out end