Module: MachineLearningWorkbench::Monkey::NArrayOuterFlattable

Defined in:
lib/machine_learning_workbench/monkey.rb

Instance Method Summary collapse

Instance Method Details

#outer_flat(other) ⇒ NArray

Flat-output generalized outer relationship. Same as ‘#outer`, but the result is a 2-dim matrix of the interactions between all the elements in `self` (as rows) and all the elements in `other` (as columns)

Parameters:

  • other (NArray)

    other matrix

Returns:

Raises:

  • (ArgumentError)


234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/machine_learning_workbench/monkey.rb', line 234

def outer_flat other
  # TODO: Xumo::NArray should be able to implement this with `#outer` and some other
  # function to flatten the right layer -- much faster
  raise ArgumentError, "Need to pass an operand block" unless block_given?
  self.class.zeros([self.size, other.size]).tap do |ret|
    self.size.times do |r|
      other.size.times do |c|
        ret[r,c] = yield self[r], other[c]
      end
    end
  end
end