Method: Daru::Vector#initialize
- Defined in:
- lib/daru/vector.rb
#initialize(source, opts = {}) ⇒ Vector
Create a Vector object.
Arguments
Hash. If Array, a numeric index will be created if not supplied in the options. Specifying more index elements than actual values in source will insert nil into the surplus index elements. When a Hash is specified, the keys of the Hash are taken as the index elements and the corresponding values as the values that populate the vector.
Options
-
:name- Name of the vector -
:index- Index of the vector -
:dtype- The underlying data type. Can be :array, :nmatrix or :gsl.
Default :array.
-
:nm_dtype- For NMatrix, the data type of the numbers. See the NMatrix docs for
further information on supported data type.
-
:missing_values- An Array of the values that are to be treated as ‘missing’.
nil is the default missing value.
Usage
vecarr = Daru::Vector.new [1,2,3,4], index: [:a, :e, :i, :o]
vechsh = Daru::Vector.new({a: 1, e: 2, i: 3, o: 4})
187 188 189 190 191 192 193 194 195 196 |
# File 'lib/daru/vector.rb', line 187 def initialize source, opts={} if opts[:type] == :category # Initialize category type vector extend Daru::Category initialize_category source, opts else # Initialize non-category type vector initialize_vector source, opts end end |