module Digiproc::CoreExtensions::ArrayExtension::DotProduct

Public Instance Methods

dot(arr) click to toggle source

Take the dot product of self another Array (allow complex numbers). They must be the same size. Returns a scalar

myArray.dot(anotherArray) # => Float
# File lib/extensions/core_extensions.rb, line 9
def dot(arr)
    raise ArgumentError.new("Array sizes must be equal") if self.size != arr.size
    output = []
    self.each_with_index do |o,i|
        output << o * arr[i].conjugate
    end
    output.sum
end