Method: NVector.seq

Defined in:
lib/nmatrix/shortcuts.rb

.seq(size, dtype = :int64) ⇒ Object

call-seq:

seq(n) -> NVector
seq(n, dtype) -> NVector

Creates a vector with a sequence of n integers starting at zero. You can choose other types based on the dtype parameter.

  • Arguments :

    • n -> Number of integers in the sequence.

    • dtype -> (optional) Default is :int64.

  • Returns :

    • NVector filled with n integers.

Examples:

NVector.seq(2) # =>  0
                     1

NVector.seq(3, :float32) # =>  0.0
                               1.0
                               2.0


998
999
1000
1001
1002
# File 'lib/nmatrix/shortcuts.rb', line 998

def seq(size, dtype = :int64)
  values = (0 ... size).to_a

  NMatrix.new([size,1], values, dtype: dtype)
end