Method: Daru::Maths::Statistics::Vector#index_of_min

Defined in:
lib/daru/maths/statistics/vector.rb

#index_of_min(size = nil, &block) ⇒ Object

Returns the index of the minimum value(s) present in the vector, with an optional comparator block.

Examples:


dv = Daru::Vector.new (["Tyrion", "Daenerys", "Jon Starkgaryen"]), index: Daru::Index.new([:t, :d, :j])
#=>
#   #<Daru::Vector(3)>
#       t   Tyrion
#       d   Daenerys
#       j   Jon Starkgaryen

dv.index_of_min
#=> :d

dv.index_of_min(2) { |a,b| a.size <=> b.size }
#=> [:t, :d]

Parameters:

  • size (Integer) (defaults to: nil)

    Number of minimum indices to return. Defaults to nil.



310
311
312
313
314
# File 'lib/daru/maths/statistics/vector.rb', line 310

def index_of_min(size=nil,&block)
  vals = min(size, &block)
  dv   = reject_values(*Daru::MISSING_VALUES)
  vals.is_a?(Array) ? (vals.map { |x| dv.index_of(x) }) : dv.index_of(vals)
end