Class: NMatrix

Inherits:
Object
  • Object
show all
Defined in:
lib/nmatrix/rowcol.rb

Instance Method Summary collapse

Instance Method Details

#column(col_number, get_by = :copy) ⇒ Object Also known as: col



27
28
29
30
31
32
33
34
35
36
37
38
39
# 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

#internal_columnObject



25
# File 'lib/nmatrix/rowcol.rb', line 25

alias_method :internal_column, :column

#internal_rowObject



5
# File 'lib/nmatrix/rowcol.rb', line 5

alias_method :internal_row, :row

#row(row_number, get_by = :copy) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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